Continuation of Hacking With Swift 100 Days of Swift
Day 8 (and 9) - Structs
In swift structs are the most commonly used data type. Almost everything is a struct from integers to strings.
To declare a struct it is done like this: struct Person { var name: String}
and initialize it we can do it this way: var person = Person(name: "Davmi)"
.
Structs the same way they contain properties, can have calculated properties, and not only that but methods and even static members too. What is more surprising is that you can even have access modifiers for structs, this makes me want to wonder what are the differences between a struct and a class?.
The most important thing one can find in a struct is the observables didSet
and willSet
these 2 will trigger themselves as when either a property has changed or a property will change, in my opinion these are the best features of the language.
Top comments (0)