Asphys
Asphys

Reputation: 185

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.

Upvotes: 0

Views: 261

Answers (1)

Eric
Eric

Reputation: 1213

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 enter image description here

enter image description here This probably isn't the best solution, but it is the best one I know.

Upvotes: 1

Related Questions