这是我的代码:
if GKLocalPlayer.localPlayer().authenticated {
if mode == 60 {
var scoreReporter2 = GKScore(leaderboardIdentifier: "countrymaster60") //leaderboard id here
scoreReporter2.value = Int64(score) //score variable here (same as above)
var scoreArray: [GKScore] = [scoreReporter2]
GKScore.reportScores(scoreArray, withCompletionHandler: {(error : NSError!) -> Void in
if error != nil {
print("error")
}
它给出的错误信息:
Cannot invoke 'reportScores' with an argument list of type '([GKScore], withCompletionHandler: (NSError!) -> Void)'
有什么建议吗?
最佳答案
文档说方法签名是:
class func reportScores(_ scores: [GKScore], withCompletionHandler completionHandler: ((NSError?) -> Void)?)
因此您需要将完成处理程序中的 error
变量设为可选。
改变
GKScore.reportScores(scoreArray, withCompletionHandler: {(error : NSError!) -> Void in
对于
GKScore.reportScores(scoreArray, withCompletionHandler: {(error : NSError?) -> Void in
关于ios - 更新到 Swift 2 后,Game Center 不接受我的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32906413/