Install Skillz for Swift

Swift is a newer alternative to Objective-C for creating iOS apps. Fortunately, it is extremely easy to make our Objective-C SDK work nicely with Swift with just one extra file.

 

Step 1: Bring the Skillz bridging header into your project

Open up the SDK and navigate to the Swift folder. Drag the header file inside that folder into your Swift project, in XCode’s Project Navigator pane. Make sure that the “Copy items if needed” checkbox is checked so that the file is copied into the project root.

If you already have a bridging header, just copy the code from our header into yours. You may want to delete any duplicate import statements.

Step 2: Set the project to use the bridging header

Now that the header is in our project, we have to tell XCode to use it as a bridging header.

Go to the bottom of the project’s build settings. Under Swift Compiler - Code Generation is the Objective-C Bridging Header setting. Set this to point to the location of the header relative to the project root.

After completing these steps, the SKillz SDK should be properly included in your Swift project and you should be able to use it without errors.

Now, perform the Skillz integration just like an Objective-C project, but with Swift syntax. If you are unsure how certain SkillzDelegate callbacks transfer to Swift syntax, take advantage of XCode’s autocomplete.

Example: tournamentWillBegin in Objective C and Swift.

The functions in Swift line up with the same functions in the Objective C documentation.

So for example in Objective C you would need your AppDelegate to implement the SkillzDelegate function:

- (void)tournamentWillBegin:(NSDictionary *)gameParameters
withMatchInfo:(SKZMatchInfo *)matchInfo
{
// This code is called when a player starts a game in the Skillz portal.
NSLog(@"Game Parameters: %@", gameParameters);
NSLog(@"Now starting a game…");

// INCLUDE CODE HERE TO START YOUR GAME
// …..
// …..
// …..
// END OF CODE TO START GAME
}

For Swift you will implement the same function inside your AppDelegate.swift, using Swift syntax:

func tournamentWillBegin(_ gameParameters: [AnyHashable : Any]!, with matchInfo: SKZMatchInfo!) 
{
print("Game Parameters: \(gameParameters as Optional)")
print("Starting Skillz Game")


// Your code goes here to start your game!
}