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.

Master iOS 11 now!

My book Practical iOS 11 gives you seven complete coding projects that teach all the major new features in iOS 11 in a smart, practical way.

Click here to visit the Hacking with Swift store >>