Structs
#set #get #willSet #didSet #newValue #oldValue #method #property #StoredProperty #ComputedProperty #staticproperty #staticmethod
Overview
Struct 's are simpler and faster than classes.
For SwiftUI Views we should use Struct rather than Class.
Stored Property vs Computed Property
Stored Property (a data to be used later)
Computed Property (fresh calculation / depends on other properties)
ReCalculates the property everytime the struct accessed
They accessed like Stored Properties but act like Methods because they run some code based on properties
* Variables and Constants in Structs are Properties
Lazy Properties
Methods
set / get
willSet / didSet
Property observers that take action, when about to change (willSet) and after the change (didSet).
It is quite useful when a property constantly needs to print during those change stages.
Do not forget that every time didSet and willSet trigger app takes action, so do not add so much work on them for sake of not having performance issues.
Example for didSet
...
If any change in blurAmount run didSet
Example for willSet
Sources: HWS,
newValue / oldValue
static let & static var & static func
The main davantage of static over regular is you can you use let & var & func across the app, whereever you need them.
private static ??? #learn
Sources
self vs Self
self: The current value of struct
values: 56, "Siirt", true
Self: The current type of struct
types: Int, String, Bool
Sources
Sources
Videos
Articles / Documents
See Also
Last updated