April 2015
Intermediate to advanced
556 pages
17h 47m
English
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 decryptData(_:) are required; schemeName is optional.
If you wanted to make a class conform to both the Encryptable protocol and the NSCoding protocol, the class would begin like this:
class SerializableObject: NSCoding, ...
Read now
Unlock full access