1

What exactly does this line do:

id <ViewControllerDelegate> delegate

It's always declared as an instance variable in the viewcontroller that implements the delegate protocol, don't understand what it does though.

Thanks

Woodstock
  • 22,184
  • 15
  • 80
  • 118

2 Answers2

2

It means delegate is an object which implements ViewControllerDelegate protocol methods. It helps the compiler to know the methods delegate is supposed to implement.

It's useful for checking type safety at compilation time and helps with autocompletion too.

Costique
  • 23,712
  • 4
  • 76
  • 79
Marcio
  • 1,979
  • 15
  • 25
1

It means that any methods or properties declared in the protocol can also be handled in the delegate. Typically setting a delegate would mean that those delegate methods are called by any instances that conform to the protocol.

A table view, for example, requires you to implement a delegate, typically on 'self'. Doing so means you inherit those properties and / or methods provided in that protocol. This is how you get those magical, - (UITableView *)table... methods. That's the basic idea of it.

Also, you can take a look at this answer. Hope that helps!

Community
  • 1
  • 1
jfuellert
  • 550
  • 4
  • 10