Skip to content

Latest commit

 

History

History
27 lines (19 loc) · 1.21 KB

Day9.md

File metadata and controls

27 lines (19 loc) · 1.21 KB

Day 9 - HackingWithSwift - 100DaysOfSwiftUI Challenge

I choose a lazy person to do a hard job, Because a lazy person will find an easy way to do it. - Bill Gates

Structs - Part II

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 100DaysOfSwiftUI!