Last active
November 3, 2015 11:21
-
-
Save venj/3b6bce6112711105b33f to your computer and use it in GitHub Desktop.
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
let number:NSNumber? = NSNumber(longLong: 3_000_000_000) // May came from Objective-C | |
guard let unwrappedNumber = number as? Int else { return } | |
print(unwrappedNumber) | |
// get -1294967296 on 32-bit platform | |
let numberStr = "3000000000" | |
let anotherNumber = Int(numberStr) | |
print("\(anotherNumber)") | |
// get nil on 32-bit platform | |
guard let unwrappedLong = number?.longLongValue else { return } | |
print("\(unwrappedLong)") | |
// now works on both 32-bit and 64 bit. | |
// unwrappedLong is Int64 on 32-bit platform | |
// Int and Int64 is actually the same on 64-bit platform |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment