使用Swift对GameKit本地玩家进行身份验证 [英] Authenticate GameKit local player using swift
本文介绍了使用Swift对GameKit本地玩家进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想快速迁移游戏,我遇到的唯一麻烦是积木/盒盖.这是我不了解的语法,而在目标C中,我将使用:
Im looking to migrate a game over to swift, the only trouble I am having is with blocks/closures. It's the syntax I just don't understand, whereas in Objective C I would use:
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
if (viewController != nil) {
[self presentViewController:viewController animated:YES completion:nil];
}
}
等但是我不确定如何在Swift中进行相同的操作.我知道这很简单,但是即使阅读了Swift的书并亲自搜索了一下,我还是无法使它正常工作.我只是一个业余程序员,所以我还远远不够完美.
etc.etc. but I'm not sure how to go about doing the same in Swift. I know it's simple but I just can't get it to work, even after reading the Swift book and googling answers myself. I'm only a hobbyist programmer so I'm far from perfect at all this.
任何帮助将不胜感激.
推荐答案
这是您在Swift中的操作方式:
This is how you would do it in Swift:
var localPlayer = CGLocalPlayer.localPlayer()
localPlayer.authenticateHandler = {(viewController : UIViewController!, error : NSError!) -> Void in
//handle authentication
}
闭包文档可以在 查看全文