Create the Game Center Helper

Switch back to the Xcode hog project, and in the Project Navigator, just below the Assets.xcassets asset catalog, create a new group (N). Name this group Game Center; this is where you’ll put all of your Game Center–related code.

Inside the new group, create a new file (N) using the iOS Swift File template. Name the new file GameKitHelper.swift and replace its contents with the following code:

 import​ ​GameKit
 
 class​ ​GameKitHelper​: ​NSObject​ {
 
 // Shared GameKit Helper
 static​ ​let​ shared: ​GameKitHelper​ = {
 let​ instance = ​GameKitHelper​()
 
 return​ instance
  }()
 }

This code is the start of your new GameKit helper class; it sets up the shared instance property, which you’ll use ...

Get Apple Game Frameworks and Technologies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.