I went to open the pizza demo to get ready for my next post and was greeted by 10 compiler error messages, all the same.
'IBOutlet' property has non-optional type 'UILabel'
When you declare an outlet in Swift, the compiler automatically converts the type to a weak implicitly unwrapped optional and assigns it an initial value of nil. In effect, the compiler replaces @IBOutlet var name: Type with @IBOutlet weak var name: Type! = nil.
When I began to write the last post, and every post before then, this was valid code:
@IBOutlet var priceLabel : UILabel
and Xcode would change this to
@IBOutlet weak var priceLabel : UILabel! = nil
However, if you control drag an outlet for a label in beta 4 this happens:
@IBOutlet var priceLabel : UILabel!
It’s an understandable change, and does make for clarity. UILabels are optionals, and should be marked as such. So every outlet you enter into code now needs to be declared optional, Xcode is no longer doing it for you, unless you control drag the outlet.
I’ll go back and fix code for previous lessons as soon as I can, but that is what going on if you get ten or more error messages on some of my previous code.
Oh, and one other, small thing:
The range operator was changed too. The
.. is now
..< Xcode will suggest that change for you when you load code.
Update August 4, 2014 — I changed all the github code to the correct versions. I now have to go back and do the same for the blogs themselves.