Swift Package Index


GameKit (GameCenter) for SwiftUI


  • The latest stable release is 0.2.0. Released about 2 months ago.
  • The last commit to main was about 1 month ago.

Swift Version Compatibility

  • 0.2.0 and main
    5.3
    5.2
    5.1
    5.0
    4.2
Full build results

Platform Compatibility

  • 0.2.0 and main
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS
Full build results

GameKitUI.swift

GameKit (GameCenter) helper for SwiftUI

GameKitUI is created and maintaned with ❥ by Sascha Muellner.


Swift codecov Platforms License Version Swift Version SPM compatible README

What?

This is a Swift package with support for iOS/macOS/tvOS that allows to use GameKit with SwiftUI.

Requirements

The latest version of GameKitUI requires:

  • Swift 5+
  • iOS 13+
  • Xcode 11+

Installation

Swift Package Manager

Using SPM add the following to your dependencies

'GameKitUI', 'master', 'https://github.com/smuellner/GameKitUI.swift.git'

How to use?

GameCenter Authentication

To authenticate the player with GameCenter just show the authentication view GKAuthenticationView.

import SwiftUI
import GameKitUI

struct ContentView: View {
	var body: some View {
		GKAuthenticationView { (state) in
			switch state {
			    case .started:
			    	print("Authentication Started")
			    	break
			    case .failed:
			    	print("Failed")
			    	break
			    case .deauthenticated:
					print("Deauthenticated")
			      	break
			    case .succeeded:
			    	break
			}
		} failed: { (error) in
			print("Failed: \(error.localizedDescription)")
		} authenticated: { (playerName) in
			print("Hello \(playerName)")
		}
	}
}

GameKit MatchMaker

Match making for a live match can be initiated via the GKMatchMakerView.

import SwiftUI
import GameKitUI

struct ContentView: View {
	var body: some View {
		GKMatchMakerView(
                    minPlayers: 2,
                    maxPlayers: 4,
                    inviteMessage: "Let us play together!"
                ) {
                    print("Player Canceled")
                } failed: { (error) in
                    print("Match Making Failed: \(error.localizedDescription)")
                } started: { (match) in
                    print("Match Started")
                }
	}
}

GameKit TurnBasedMatchmaker

To start a turn based match use GKTurnBasedMatchmakerView.

import SwiftUI
import GameKitUI

struct ContentView: View {
	var body: some View {
		GKTurnBasedMatchmakerView(
                    minPlayers: 2,
                    maxPlayers: 4,
                    inviteMessage: "Let us play together!"
                ) {
                    print("Player Canceled")
                } failed: { (error) in
                    print("Match Making Failed: \(error.localizedDescription)")
                } started: { (match) in
                    print("Match Started")
                }
	}
}

Documentation