简体   繁体   中英

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:

Type 'Battle' does not conform to protocol '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.

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 在此处输入图片说明

在此处输入图片说明 This probably isn't the best solution, but it is the best one I know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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