简体   繁体   English

类型“战斗”不符合协议“ GKMatchmakerViewControllerDelegate”

[英]Type 'Battle' does not conform to protocol 'GKMatchmakerViewControllerDelegate'

I have this code: 我有以下代码:

import GameKit

class Battle: UIViewController, GKMatchmakerViewControllerDelegate {


func hostMatch(sender: AnyObject) {
    var request: GKMatchRequest = GKMatchRequest()
    request.minPlayers = 2
    request.maxPlayers = 2
    var mmvc: GKMatchmakerViewController = GKMatchmakerViewController(matchRequest: request)!
    mmvc.matchmakerDelegate = self
    self.presentViewController(mmvc, animated: true, completion: { _ in })
}


}

Which should show the Game Center standard user interface for searching for players, but for some reason it keeps giving me this error: 该页面应显示用于搜索玩家的Game Center标准用户界面,但由于某些原因,它始终提示我此错误:

Type 'Battle' does not conform to protocol 'GKMatchmakerViewControllerDelegate' 类型“战斗”不符合协议“ GKMatchmakerViewControllerDelegate”

That is the whole error and i have no idea how to fix it. 那就是整个错误,我不知道如何解决。 If you have an answer, please explain it well so i can understand it. 如果您有答案,请解释清楚,以便我理解。

You are getting that error because your class doesn't have all the functions (or variables) the protocol GKMatchkmakerViewControllerDelegate wants your class to have. 之所以收到该错误,是因为您的类没有GKMatchkmakerViewControllerDelegate协议希望您的类具有的所有函数(或变量)。

To find out which functions or variables you need to include, command-click on the protocol name. 要找出您需要包括哪些功能或变量, 在协议名称上单击命令 You then see the protocol declaration. 然后,您会看到协议声明。 All the normal functions listed there are required inside your class. 列出的所有正常功能在您的班级中是必需的。

functions that start with the optional keyword aren't required 不需要以optional关键字开头的函数 在此处输入图片说明

在此处输入图片说明 This probably isn't the best solution, but it is the best one I know. 这可能不是最好的解决方案,但这是我所知道的最好的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM