Updated for Xcode 15
Now that you understand how protocols and extensions work, it’s time to pause our learning and take on a challenge so you can put it all into practice.
Your challenge is this: make a protocol that describes a building, adding various properties and methods, then create two structs, House
and Office
, that conform to it. Your protocol should require the following:
I’ll provide some hints in a moment, but first I recommend you go ahead and try it yourself.
Hacking with Swift+ subscribers can get a complete video solution for this checkpoint here: Solution to Checkpoint 8. If you don’t already subscribe, you can start a free trial today.
Still here? Okay, here are some hints:
{ get }
or { get set }
.BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.