Apologies ahead of time if this is a completely off-the-mark question, or if I'm not including enough information - I'm very new to iOS development (and Objective-C), and have a habit of jumping into the deep end...
I'm having trouble understanding the "callDelegate" code in GameCenterManager.m that's in the GKTapper Sample Code and also provided in this tuts+ tutorial: http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-game-center-achievements-and-leaderboards-part-2/
This is the code:
- (void) callDelegate: (SEL) selector withArg: (id) arg error: (NSError*) err
{
assert([NSThread isMainThread]);
if([delegate respondsToSelector: selector])
{
if(arg != NULL)
{
[delegate performSelector: selector withObject: arg withObject: err];
}
else
{
[delegate performSelector: selector withObject: err];
}
}
else
{
NSLog(@"Missed Method");
}
}
My app always logs that "Missed Method" line, but I'm not sure what this callDelegate code is actually doing (so I can't fix it). I figure the best way forward is to learn what this is actually doing, and get better output than 'Missed Method'...
One caveat is that my app is currently using Game Center in sandbox mode, since I'm still developing it. This 'Missed Method' line might be expected in this situation - I'm not sure of that, either.
Would anybody be able to translate this code into paragraph form? I'm particularly unsure about the '[delegate respondsToSelector: selector]' piece.
Alternatively, would anybody be able to rewrite the NSLog line so that it outputs more/relevant detail about the problem? I tried this in the hopes of seeing which selector is not going through 'respondsToSelector' properly, but it didn't seem to work:
NSLog(@"Missed Method, %@", selector);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…