I am relatively new to Objective-C.
I have come to a code on the web that has something like this on rootViewController.m (this is a navigationController based app).
@interface RootViewController (CManagerDelegate) <CManagerDelegate>
@end
@interface RootViewController (PViewDelegate) <PViewDelegate>
@end
two questions:
- what are these lines doing in the beginning of rootViewController.m
- what are these lines doing in code? Please explain the stuff in parenthesis and between <> in this particular case.
thanks.
In one sentence: The code you posted makes the
RootViewControllerclass privately conform to some delegate protocols.Delegate protocols are used to let a class declare the fact that it understands the messages from another class’s objects. For example, a view controller can declare that it understands a gesture recognizer’s delegate messages.
The fact that the class internally uses the gesture recognizer is often an implementation detail not relevant to other clients of the class. It is best not to publish this fact in the public interface but put it into the implementation (.m file).
Categories (and class extensions) let you do exactly this: Make a class conform to a protocol without changing the main
@interface.A nice and elegant solution!