Convert between CGFloat and String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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