I see a lot of code such as the following as of late:
id<foo> aBar;
Typically this is something I’d see in a class declaration, such as:
@interface bar : UIViewController <UITableViewDelegate, UITableViewDataSource>
Does the above mean that aBar might be an instance of class bar and promises to have all of the methods declared in the foo protocol?
Close. It means that
aBarwill be an instance of a class that conforms to protocolfoo. It could bebar(if that class conformed tofoo) or another class that conforms tofoo. All you know from that declaration is thataBarconforms to the protocol.Also, these are only checked at compile-time, not runtime. It is possible to put an object in
aBarthat is not an instance of a class that conforms tofoo. But the compiler will warn you about it in most cases.