DEV Community

Cover image for 9 out of 100 Days of SwiftUI

9 out of 100 Days of SwiftUI

ramsescabello profile image Ramsés Cabello⚡️ ・1 min read

Getting more and more complex but I'll push through a little bit more. I think I'll start to see everything coming together when the projects start.

Here's some notes on methods & initializers:


Are special methods that provide different ways to create a struct. The default initializer /memberwise initializer/.

struct structName {

    init() {
Enter fullscreen mode Exit fullscreen mode

Inside methods, you get a special constant called self, which points to whatever instance of the struct is currently being used. This self value is particularly useful when creating initializers that have the same parameter names as your property.

As a performance optimization you can create some properties only when needed. Place the command lazy before the property.

Inside structs, you can create static classes that will be equal for all instances of the struct. Use the word static before the property of the struct.

You can call properties from the struct by using the following structure: struct.Property

To avoid reading a specific property outside of the struct; you can use the keyword private before the property. To achieve the opposite, use the keyword public.

Discussion (0)

Editor guide