swift String 转 NSNumber

Swift 3.0

let someString = "42222222222"
if let myInteger = Int(someString) {
    let myNumber = NSNumber(value:myInteger)
}

Swift 2.0

Use the Int() initialiser like this.

let someString = "42222222222"
if let myInteger = Int(someString) {
    let myNumber = NSNumber(integer:myInteger)
    print(myNumber)
} else {
    print("'\(someString)' did not convert to an Int")
}

你可能感兴趣的:(swift String 转 NSNumber)