FREE TRIAL: Accelerate your app development career with Hacking with Swift+! >>

DAY 12

Classes


At first, classes seem very similar to structs because we use them to create new data types with properties and methods. However, they introduce a new, important, and complex feature called inheritance – the ability to make one class build on the foundations of another.

This is a powerful feature, there’s no doubt about it, and there is no way to avoid using classes when you start building real iOS apps. But please remember to keep your code simple: just because a feature exists, it doesn’t mean you need to use it. As Martin Fowler wrote, “any fool can write code that a computer can understand, but good programmers write code that humans can understand.”

I’ve already said that SwiftUI uses structs extensively for its UI design. Well, it uses classes extensively for its data: when you show data from some object on the screen, or when you pass data between your layouts, you’ll usually be using classes.

I should add: if you’ve ever worked with UIKit before, this will be a remarkable turnaround for you – in UIKit we normally use classes for UI design and structs for data. So, if you thought perhaps you could skip a day here and there I’m sorry to say that you can’t: this is all required.

Today you have six tutorials to work through, and you’ll meet classes, inheritance, deinitializers, and more. Once you’ve watched each video and completed any optional extra reading you wanted, there are short tests to help make sure you’ve understood what was taught.

  1. How to create your own classes
  2. How to make one class inherit from another
  3. How to add initializers for classes
  4. How to copy classes
  5. How to create a deinitializer for a class
  6. How to work with variables inside classes
  7. Summary: Classes
  8. Checkpoint 7

Have some questions about classes?

Hit Send below to start a virtual conversation with me.

Need help? Tweet me @twostraws!

 

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for iOS devs who want to become complete senior developers — from October 18th to 24th. Learn how to apply iOS app architecture patterns through a series of lectures and practical coding sessions.

Learn more

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

100 Days of SwiftUI


The 100 Days of SwiftUI is a free collection of videos, tutorials, tests, and more to help you learn SwiftUI faster. Click here to learn more, or watch the video below.

Back to 100 Days of SwiftUI

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.