Game Development Reference
In-Depth Information
Now, about error handling, you'll notice that GameKitHelper uses the
setLastError method wherever there's an error object returned. This lets the del-
egate class check whether any error occurred through the lastError property. If it's
nil , then there was no error.
However, only the last error object is kept around, and the next method returning an
NSError object will replace the previous error, so it's crucial to check for the
lastError property right away if error handling is important in that particular case.
In some cases, you can safely ignore errors. They might lead only to temporary prob-
lems, like an empty friends list. Regardless, the setLastError message copies the
new error and then prints out diagnostic information so you can always keep an eye on
the kinds of errors that occur during development:
-(void) setLastError:(NSError*)error
{
lastError = error.copy;
if (lastError != nil)
NSLog(@"GameKitHelper ERROR: %@", [lastError userInfo].description);
}
If you receive an error and want to know more about it, refer to Apple's Game Kit
Constants Reference, which describes the error constants defined in the GameKit/
GKError.h header file: http://developer.apple.com/library/ios/
#documentation/GameKit/Reference/GameKit_ConstantsRef/Re-
ference/reference.html .
After the local player has successfully signed in, you can access his friend list, leader-
boards, and achievements. But before I get to that, let's sidestep for a moment and re-
view the important aspects of block objects.
Block Objects
The inline method shown in Listing 14-5 is called a block object , commonly referred to
simply as a block . You might have heard of closures , anonymous functions , or lambda
in other languages, which are essentially the same concept. Block objects are a C-lan-
guage extension introduced by Apple to make multithreaded and asynchronous pro-
Search Nedrilad ::




Custom Search