From the course: Cocoa with Swift 3 Essential Training
Unlock this course with a free trial
Join today to access over 22,500 courses taught by industry experts.
Custom delegate classes
From the course: Cocoa with Swift 3 Essential Training
Custom delegate classes
- [Instructor] So let's look at writing a custom delegation protocol and implementing it in a custom object. So here in my app I just have a button and it's connected to this method clickedButton in my AppDelegate class. So the first step is to define the delegate protocol. And I'm going to do that in AppDelegate.swift. And I'm going to do it right underneath my import statement. So I'll use the protocol keyword and then when swift protocol is highlighted I'll press return on my keyboard. And then I need to give it a name. I'm going to call this CustomDelegate. And for requirements, I'm just going to declare a customDelegateExample. And that's it. So now we've declared our protocol. Now what we're going to do is create a custom class. So I'll press Command N, and then under macOS I'll choose Cocoa Class. Hit next. We'll call this OtherObject. And it can be a Subclass of NSObject, Language Swift. And hit Next. Hit Create to create it in the default location. So we have…
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.