This method demonstrates how to report a score to Game Center:
func submitScore(score: Int, leaderboardID: String) {
if GKLocalPlayer.localPlayer().authenticated {
// Create and initialize a GKScore object
let gkScore = GKScore(leaderboardIdentifier: leaderboardID)
gkScore.value = Int64(score)
// Report the score
GKScore.reportScores([gkScore], withCompletionHandler: { (error: NSError!) -> Void in
if error != nil {
println("Error: \(error.localizedDescription)")
}
else {
println("Score Reported")
}
})
}
}
All the best!
Kevin McNeish
Author of
Learn to Code in Swift:
https://itunes.apple.com/us/book/learn-to-code-in-swift/id942956811?mt=11Check out our
Robot Tic-Tac-Toe app:
https://itunes.apple.com/us/app/robot-tic-tac-toe/id990638517?mt=8