"NSNumber" does not convert to "Int" Swift
I realize this is an older question and you probably figured it out by now, but having similar issues, I figured I'd post an answer for posterity.
Swift (as far as I know) is still undergoing design changes as a programming language, and one thing I noticed was that I needed to start wrapping my int inside a function Int()
. Therefore, your example might need to look something like this:
var score: NSNumber?
score = NSNumber(integer:score!) + 1
Edit:
To try and explain why we should be doing this, I believe it is because score
- it is NSNumber()
, which can have various number forms. NSNumber(integer:score!)
re-wraps score!
as an integer, in particular, allowing us to use integers in it in mathematical equations.
source to share