Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Convert between CGFloat and String
// Note:
// When you found that you cannot cast/convert between CGFloat and String, you may add following piece of code
// to make your life a bit easier.
//
// if let number = CGFloat("1234.5") {
// }
// let string = String(CGFloat.pi)
//
extension CGFloat: LosslessStringConvertible {
public init?(_ description: String) {
if let number = Double(description) { self = CGFloat(number) }
else { return nil }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment