我需要从游戏中心检索玩家提交的最高分数。我想我在目标C中找到了答案,但是我不知道怎么用swift来写,因为我对这个还不太熟悉。有人能帮我把下面的代码翻译成swift吗?提前谢谢你。

GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init];
    if (leaderboardRequest != nil) {
        [leaderboardRequest loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error){
            if (error != nil) {
                //Handle error
            }
            else{
                [delegate onLocalPlayerScoreReceived:leaderboardRequest.localPlayerScore];
            }
        }];
    }

最佳答案

以下是对斯威夫特的直译:

let leaderboardRequest = GKLeaderboard() as GKLeaderboard!
if leaderboardRequest != nil
{
    leaderboardRequest.loadScoresWithCompletionHandler({ (scores:[AnyObject]!, error:NSError!) -> Void in
        if error != nil
        {
            //handle error
        }
        else
        {
            delegate.onLocalPlayerScoreReceived(leaderboardRequest.localPlayerScore)
        }
    })
}

关于ios - swift 从Game Center检索用户最高得分,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25920740/

10-13 07:34