-1

I have a cordite model. One of the attributes is an NSNumber,

@NSManaged var playerOneScore: NSNumber 

I'm trying to fetch this and store it in a text label.

playerOnePar.text = myArray[0].valueForKey("playerOneScore") as String

It doesn't like this. Im guessing an NSNumber can't be casted into a String. However, it doesn't like this. Thoughts on this with the new swift language?

candidaMan
  • 791
  • 1
  • 7
  • 12

1 Answers1

1

Swift automatically bridges certain native number types, such as Int and Float, to NSNumber.

Ok, Try this out , I tested this and worked as expacted.

    let number: NSNumber = myArray[0].valueForKey("playerOneScore")
    let intNumber: Int = number
    playerOnePar.text = String(intNumber) 
Ezimet
  • 5,058
  • 4
  • 23
  • 29