.stringValue is a way to extract Integer into a string value, but as String will not work for this. And if you use as String , then Xcode will force you to add ! with as , which is not very good and it will never succeed, and this will crash your application. you cannot impose Int on String . He will always fail. That is why when you do as! String as! String , this causes the application to crash.
So casting here is not a good idea.
And here are some more ways to extract Integer into a string value:
let i : Int = 5 // 5 let firstWay = i.description // "5" let anotherWay = "\(i)" // "5" let thirdWay = String(i) // "5"
Here you cannot use let forthway = i.stringValue , because Int does not have a member named stringValue
But you can do the same with anyObject , as shown below:
let i : AnyObject = 5 // 5 let firstWay = i.description // "5" let anotherWay = "\(i)" // "5" let thirdWay = String(i) // "5" let forthway = i.stringValue // "5" // now this will work.
source share