Optional Protocol Prerequisites

If you peruse the Swift pseudo-code by Command+clicking protocols, you will see that a lot of them have optional requirements. For example, when you start a new project of any type, you can inspect UIApplicationDelegate, and you should see something like what Figure 8.1 shows.

Image

Figure 8.1 The UIApplicationDelegate protocol.

You can see that most of the methods of this protocol are optional and therefore do not need to be implemented. You can mark any method as optional so that the compiler will not throw an error if a method is not implemented. Even though you can’t see it in Figure 8.1, you need to mark a protocol ...

Get Learning Swift™ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.