The Situation
My custom controller class has the following method:
- (void)requestViewControllerWithIdentifier:(NSString *)identifier fromObject:(id)object;
This causes object
to receive this message:
- (UIViewController *)viewControllerWithIdentifier:(NSString *)identifier;
The Problem
Right now, object
is just an id
so there's no guarantee that it actually implements that method, and I get a compiler warning when I send the message.
The Solution
I came up with two solutions myself:
- Use a protocol.
- Make
id
anNSObject
and create a category forNSObject
.
They are both fine solutions probably and I don't mind choosing one of them, but...
The Question
...I noticed Apple is doing something odd in their GameKit API. GKSession
has the following method:
- (void)setDataReceiveHandler:(id)handler withContext:(void *)context
handler
is just an id
, but Apple actually requires it to implement this method:
- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context;
Without making use of any protocol or category! I'm wondering how and why would they do this? Why don't use a protocol? Do they enforce the method in some other way? If I were to do this, how can I suppress the compiler warning?