Swift version: 5.10
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.
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
Available from iOS 8.0
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.
Link copied to your pasteboard.