Conclusion

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

In the last demo, you learned about the lifecycle of reference type instances. You used the deinit function to know when an instance is getting deleted. You learned how reference types are different when they get allocated in memory compared to value types.

In this lesson, you built an small app in a playground to store contacts. You used structs, which are value types, and classes, which are reference types. You saw the difference between them when you assigned an instance of either type to a new variable and then changed the value.

Variables of reference types allow you to access the same value from multiple parts of your app. Value types make a copy of their value for each variable you assign them to. Understanding them properly allows you to decide which to use in your code.

Understanding how memory works helps you write better code and use the device’s resources better. That allows you to create better and more stable apps.

In this lesson, you covered the following learning objectives:

  • Define the difference between classes and structs.
  • Implement classes and structs with properties and methods.
  • Use structs and classes to create reusable and efficient code.
  • Understand how your variables reserve memory and how classes and structs are stored.

In the next lesson, you’ll write code to solve a puzzle, evaluate your solution, and see if you can improve it.

See forum comments
Download course materials from Github
Previous: Memory Demo Next: Structs and Classes Quiz