Declaring variables in swift

You need to use an Int, not Integer.

var year:Int
year = 2

Note: You can do this in one line

var year:Int = 2

and use type inference

var year = 2

I've been blogging a little about Swift if you're interested, starting here:

http://alblue.bandlem.com/2014/09/swift-introduction-to-the-repl.html

(You can subscribe to the feed at http://alblue.bandlem.com/Tag/swift/)


If the variable never changes, you should declare a constant instead.

let year: Int = 2

...or with type inference:

let year = 2

Note that Swift infers Int when you assign a whole number to a variable/constant and Double when you assign a fraction.

Tags:

Ios

Swift