NEW: Master Swift design patterns with my latest book! >>

How to convert radians to degrees

Written by Paul Hudson    @twostraws

Most angles in iOS are measured using radians rather than degrees, but the majority of users prefer to see degrees so you’ll need to do some conversion. The equation to convert between the two is simple enough: multiply the number by 180, then divide the result by Pi.

To make things easier, drop in this function:

func rad2deg(_ number: Double) -> Double {
    return number * 180 / .pi
}

You can now use rad2deg(5) to find 5 radians in degrees.

Available from iOS 8.0

Did this solution work for you? Please pass it on!

Other people are reading…

About the Swift Knowledge Base

This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.

Swift on the server is here

Get ahead of the game and learn server-side Swift with my latest book – build real-world projects while you learn!

Click here to visit the Hacking with Swift store >>