Protocols

For every object that can have a delegate, there is a corresponding protocol that declares the messages that the object can send its delegate. The delegate implements methods from the protocol for events it is interested in. When a class implements methods from a protocol, it is said to conform to the protocol.

(If you are coming from Java or C#, you would use the word interface instead of protocol.)

The protocol for UITextField’s delegate looks like this:

@​p​r​o​t​o​c​o​l​ ​U​I​T​e​x​t​F​i​e​l​d​D​e​l​e​g​a​t​e​ ​<​N​S​O​b​j​e​c​t​>​ @​o​p​t​i​o​n​a​l​ -​ ​(​B​O​O​L​)​t​e​x​t​F​i​e​l​d​S​h​o​u​l​d​B​e​g​i​n​E​d​i​t​i​n​g​:​(​U​I​T​e​x​t​F​i​e​l​d​ ​*​)​t​e​x​t​F​i​e​l​d​;​ -​ ​(​v​o​i​d​)​t​e​x​t​F​i​e​l​d​D​i​d​B​e​g​i​n​E​d​i​t​i​n​g​:​(​U​I​T​e​x​t​F​i​e​l​d​ ...

Get iOS Programming: 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.