swift2 - Swift 2, convert a String into an Int -
i'm using xcode 7 beta 3 , reading through swift 2.2 document. i'm trying compile example found in basics section of document:
let possiblenumber = "123" let convertednumber = int(possiblenumber) it supposed convert string optional int. xcode gives error:
cannot call value of non-function type 'int'
i working on xcode 7.2.1, knew swift 2.2 packaged xcode 7.3 beta 3, downloaded try, same error happens. so, document wrong? , how achieve string int conversion?
there nothing wrong code, tested , ran exact code in xcode 7.2:
let possiblenumber = "123" let convertednumber = int(possiblenumber) print("\(convertednumber)") it complied, ran within app of mine, , printed int value 123.
perhaps error being thrown area of code in xcode app, other code think throwing error....
perhaps not referencing version of swift think are...
note, should use if let conversion attempt:
if let convertednumber = int(possiblenumber) { } the if let should used conversion no matter how remote possibility of failure.
Comments
Post a Comment