我需要从游戏中心检索玩家的最高提交分数。我想我在目标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];
}
}];
}
答案 0 :(得分:0)
这是对Swift的直接翻译:
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)
}
})
}