How does the protocol for an instance variable work in Objective-C?

Recently, I see a lot of code, for example, the following:

id<foo> aBar;

This is usually what I see in the class declaration, for example:

@interface bar : UIViewController <UITableViewDelegate, UITableViewDataSource>

Does this mean that aBar can be an instance of the bar and promises class to have all the methods declared in the foo protocol?

+5
source share
2 answers

To close. This means that there aBarwill be an instance of a class that conforms to the protocol foo. It can be bar(if this class matches foo) or another class that matches foo. All you know from this declaration is that it aBarcomplies with the protocol.

, , . aBar, , foo. .

+16

. , , . , , , , . #.

#, .:)

0

All Articles