From the course: Swift: Delegations and Data Sources
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Delegates in watchOS
From the course: Swift: Delegations and Data Sources
Delegates in watchOS
- Instead of getting a class and sending properties like we do in iOS, watchOS requires sending values through Context. This is the big change. To send the delegate, you need to send it with a context. Let's see this in action by finishing the delegate for the watch project. Hop over to the Desserts Interface Controller and once there we'll make a protocol. So slide up to the top, and above the class we'll start a protocol. And I'm going to call it Desserts Interface Controller Delegate and it'll have one required function and that is did Finish Selecting Dessert. And that'll be an item of type OrderItem. So we have a protocol. Now we'll go into the interface controller to our properties, and I'm going to add the delegate declaration. So it'll be var delegate Desserts Interface Controller Delegate. That's going to be optional, and it'll have a value of nil. Now I can use this and so find the button pressed method, right here, and above the pop, which is a watch version of dismiss, add…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.