Reputation: 4321
I'm working on Game Center now. In Apple's Game Center Programming Guide (Listing 4-11), there is example code to retrieve the top scores of a leaderboard:
GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init];
if (leaderboardRequest != nil)
{
...
[leaderboardRequest loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) {
...
}
Is it at all necessary to check whether the returned object is nil? Will the init
ever fail and return nil?
Upvotes: 0
Views: 45
Reputation: 11
The documentation doesn't say anything about this, and if we look in the header file for GKLeaderboard (GKLeaderboard.h) it doesn't say anything about this either. The declaration for the init functions looks like this:
- (instancetype)init;
Which means that the init function will return either an instance of GKLeaderboard or nil (or any subclass to GKLeaderboard).
So the answer would be yes, you always have to check if the returned value is nil.
Upvotes: 1