GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

Classes summary

You’ve made it to the end of the eighth part of this series, so let’s summarize:

  1. Classes and structs are similar, in that they can both let you create your own types with properties and methods.
  2. One class can inherit from another, and it gains all the properties and methods of the parent class. It’s common to talk about class hierarchies – one class based on another, which itself is based on another.
  3. You can mark a class with the final keyword, which stops other classes from inheriting from it.
  4. Method overriding lets a child class replace a method in its parent class with a new implementation.
  5. When two variables point at the same class instance, they both point at the same piece of memory – changing one changes the other.
  6. Classes can have a deinitializer, which is code that gets run when an instance of the class is destroyed.
  7. Classes don’t enforce constants as strongly as structs – if a property is declared as a variable, it can be changed regardless of how the class instance was created.
Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure and A/B test your entire paywall UI without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

BUY OUR BOOKS
Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let us know!

Average rating: 4.6/5

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.