I choose a lazy person to do a hard job, Because a lazy person will find an easy way to do it. - Bill Gates
Today I learnt about:
- Initializers
- Referring to the current instance of a struct
- Lazy properties
- Static properties and methods
- Access Control
The summary of the entire day was:
- You can create your own types using structures, which can have their own properties and methods.
- You can use stored properties or use computed properties to calculate values on the fly.
- If you want to change a property inside a method, you must mark it as
mutating
. - Initializers are special methods that create structs. You get a memberwise initializer by default, but if you create your own you must give all properties a value.
- Use the
self
constant to refer to the current instance of a struct inside a method. - The
lazy
keyword tells Swift to create properties only when they are first used. - You can share properties and methods across all instances of a struct using the
static
keyword. - Access control lets you restrict what code can use properties and methods.
That's all for the Day 9 of 100DaysOfSwift!