Summary

You learned a lot about value types and reference types in this chapter. You learned what each type is and how you can use them. You learned that you can use classes, closures, structs, and enums in Swift and that each of these object types has its own pros and cons.

After learning about all types, you saw how value types and reference types compare to each other, which has shed some light on the sometimes subtle and sometimes obvious use cases for each type. You learned that structs can't be subclasses, while classes can. You also learned that passing around value types passes around copies of each instance, and passing around reference types does not copy each instance but rather passes around a pointer to the addresses in memory. Then you learned how each type is held in memory and what this means for the performance of the objects you created.

Lastly, you read about how to choose between value types and reference types by using several rules of thumb that should make choosing between structs, classes, and enums fairly straightforward without blindly picking one. The next chapter will take your Swift knowledge one step further by showing you how to write ultra-flexible code with Swift's generics.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset