402-hd-introduction-to-swift.mov
- This is a general principle in Swift, that we prefer immutability or constants by default and only really opt into mutablility or variables where things actually need to change. Now this makes your code safer in a multi-threaded environment. It also means that Swift can optimize your code more effectively because it knows what isn’t going to change and it just generally makes your code more readable, makes your intent clearer that you’re saying what is and isn’t going to vary.
Swift initializers don’t return a value. Rather, their main role to make sure that every stored property has a value by the time its initialization completes.
Non-Optional Types can’t be nil.
#403-hd-intermediate-swift.mov
Weak References tell Swift that this object isn’t responsible for keeping the object on the other end alive. And weak references in Swift are modeled as optinonal values.
Unowned References tell Swift that although I don’t have an owning stake in the object, my lift depents on it, I can’t live without my owner, my card holder.
Every value must be initialized before it is used.
Initializers handle the responsibility of fully initailizing an instance.
We always make sure we set our own properties before we call our SuperClass’s initializer.
Convenience Initializers
1 | init (color: Color, turbo: BOOl) { |
- Lazy Properties.
It will only be evaluated the time it’s accessed and only when it’s accessed and only that one time.
1 | var multiplayerManager = MultiplayerManager() |
- Initialization
Initialize all values before you use them.
Set all stored properties first, then call super.init
Designated initializers only delegate up
Convenience initializers only delegate across
Deinitializers are there…if you need them.