Sorry in advance if my terminology is off. I'm learning Swift just by converting old code from ObjC to Swift, and it bothers me that we declare a variable like this
without declaring the type, as we would in something like Java like this:
The way Swift does it makes it not very apparent what kind of data this variable refers to! Of course, there's the option of doing
but I find that pretty annoying to type and messy in comparison. Why did they change how we declare variables in such a way? Is there something having to do with how Swift works that I'm missing?
Code:
var foo = Array<AnyObject>()
Code:
Array<AnyObject> foo = Array<AnyObject>() // Not valid in Swift.
Code:
var foo:Array<AnyObject> = Array<AnyObject>() // Does same thing as first example, right?
Last edited: