mardi 10 mars 2015

In Swift, why have "as" keyword. What does it benefit? Why did they put in?

I'm aware of what "as" keyword does and how to use them. But I'm more curious in the architectural side of the "as" keyword. Why is it there? What's the huge reason? What does it help?


Example:



var objectData:NSData = NSUserDefaults.standardUserDefaults().objectForKey("myKey") as NSData


wouldn't it be better if it's:



var objectData:NSData = NSUserDefaults.standardUserDefaults().objectForKey("myKey")

Aucun commentaire:

Enregistrer un commentaire