0

I would like like to set up the matchmaking viewController of my game. To do so, I add the GKMatchmakerViewControllerDelegate delegate to my main UIViewController called Home, so that it looks like:

class Home: UIViewController, GKGameCenterControllerDelegate, GKMatchmakerViewControllerDelegate {

To load up the matchmaking interface I am using this code:

func openMatchmaker() {
    var gcViewController: GKMatchmakerViewController = GKMatchmakerViewController(rootViewController: self)

    gcViewController.matchmakerDelegate = self

    gcViewController.hosted = false
    gcViewController.matchRequest.minPlayers = 2
    gcViewController.matchRequest.maxPlayers = 2
    gcViewController.matchRequest.defaultNumberOfPlayers = 2

    self.showViewController(gcViewController, sender: self)
    self.navigationController?.pushViewController(gcViewController, animated: true)
}

Though, I receive the following error next class Home: ... to when I try to run the code. The error message says:

 Type 'Home' does not conform to protocol `GKMatchmakerViewControllerDelegate`. 

Why is that happening?

Cesare
  • 9,139
  • 16
  • 78
  • 130

2 Answers2

1

Most of the time when you get that error is because you have not implemented the required functions of the particular protocol. You can see them by command clicking on that protocol. Add the following methods:

func matchmakerViewController(viewController: GKMatchmakerViewController!,
    didFailWithError error: NSError!) {
}

func matchmakerViewController(viewController: GKMatchmakerViewController!,
    didFindHostedPlayers players: [AnyObject]!) {
}

func matchmakerViewControllerWasCancelled(viewController: GKMatchmakerViewController!) {
}

func matchmakerViewController(viewController: GKMatchmakerViewController!,
    hostedPlayerDidAccept player: GKPlayer!) {
}
Cesare
  • 9,139
  • 16
  • 78
  • 130
gasho
  • 1,926
  • 1
  • 16
  • 20
  • That's a good answer, thank you! I will be looking to implement these required methods asap. Thanks. – Cesare Feb 14 '15 at 15:03
0

The second function in the approved answer was updated in latest SDK:

func matchmakerViewController(viewController: GKMatchmakerViewController, didFindHostedPlayers players: [GKPlayer]) {
   ... 
}
Quanlong
  • 24,028
  • 16
  • 69
  • 79
jelmore
  • 1
  • 3