0

When I use this code from apple book in my playground:

let possibleNumber = "123"
let convertedNumber = Int(possibleNumber)

Xcode shows an error:

Cannot invoke "Int" with an argument of type "String"

But compiler should refer convertedNumber as optional, as I understand.

1
  • 1
    Works fine for me. What version of Xcode are you using? I'm on 7.1.1 Commented Nov 26, 2015 at 14:09

2 Answers 2

1

You must be using Swift 1.x (in Xcode 6), but the Swift book is for the last version of Swift, currently 2.1 (in Xcode 7). The String initializer for Int() wasn't available in Swift 1.

Sign up to request clarification or add additional context in comments.

Comments

0

I was able to make this work with no issues. It could be the XCode causing the issue. Try a reinstallation of the XCode.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.