For the More Curious: Creating a Protocol
Creating your own protocol is very simple. Here is a protocol with two methods.
protocol Encryptable { init(encryptedData: NSData) func encrypt() -> NSData }
The protocol would typically be defined in a file called Encryptable.swift:
If your protocol is tagged @objc
,
it is possible to add optional methods.
@objc protocol Encryptable { init(encryptedData: NSData) func encrypt() -> NSData optional func schemeName() -> String }
In this example, encryptData(_:) and ...
Get Cocoa Programming for OS X: The Big Nerd Ranch Guide 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.