From the course: Swift: Delegations and Data Sources
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Delegates in theory
From the course: Swift: Delegations and Data Sources
Delegates in theory
- [Instructor] You moved objects to the destination controller. How do you move it from the destination to the source? That's what delegates are for. When we press duke pi in the app, we need a method to return a value. With an encapsulated class you can't do that. There's no way to send that revised model back to the original controller without breaking encapsulation or NVC. The new view controller does not know anything about the class that called it. We can't send objects backwards the same way we sent them forwards. This is the problem that delegates and protocols solve by being sneaky. Imagine a special class, one that is a skeleton of a class. It declares methods in this class, but never implements them. These are protocols. We make a protocol class as a method we'll call when we finish the controller. That method will have parameters you pass back to the original view controller. In the destination view controller, make an instance of this protocol as a property of the…
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.