不兼容的指针类型发送&#39; NSArray <gkplayer * =“”> *&#39;参数类型&#39; NSArray <nsstring *> * _Nonnull&#39;

时间:2016-03-23 21:37:46

标签: ios objective-c gamekit

- (void)lookupPlayers {
    NSLog(@"Looking up %lu players...", (unsigned long)match.players.count);

    // Error on the below line
    [GKPlayer loadPlayersForIdentifiers:match.players withCompletionHandler:^(NSArray *players, NSError *error) { {

        if (error != nil) {
            NSLog(@"Error retrieving player info: %@", error.localizedDescription);
            matchStarted = NO;
            [delegate matchEnded];
        } else {

            // Populate players dict
            self.playersDict = [NSMutableDictionary dictionaryWithCapacity:players.count];
            for (GKPlayer *player in players) {
                NSLog(@"Found player: %@", player.alias);
                [playersDict setObject:player forKey:player.playerID];
            }

            // Notify delegate match can begin
            matchStarted = YES;
            [delegate matchStarted];

        }
    }];

1 个答案:

答案 0 :(得分:1)

阅读GKPlayer loadPlayersForIdentifiers:withCompletionHandler:的文档。标识符数组必须是NSString的数组,但是您传入的数组为GKPlayer

你可以这样做,从玩家阵列中获取一系列玩家ID:

NSArray *playerIds = [match.players valueForKey:@"playerID"];

然后将playerIds代替match.players传递给loadPlayersForIdentifiers:withCompletionHandler: