November 2016
Intermediate to advanced
480 pages
14h 42m
English
Take a look at this code that you entered earlier:
for i in 1...5 {
myFirstInt += 1
print("myFirstInt equals \(myFirstInt) at iteration \(i)")
}
Notice that i is not declared to be of the Int type.
It could be, as in for i: Int in 1...5, but an explicit type declaration is not necessary.
The type of i is inferred from its context (as is the let).
In this example, i is inferred to be of type Int because the specified range contains integers.
Type inference is handy: Because you will type less, you will make fewer typos. However, there are a few cases in which you need to specifically declare the type. We will highlight those when they come up. In general, however, we recommend that you take advantage ...
Read now
Unlock full access