GCOverseer

2.0.0

Observe and manage game controllers using AsyncSequence 🎮
backslash-f/gcoverseer

What's New

v2.0.0

2024-12-05T22:21:57Z

Version 2.0.0 modernizes the entire thing:

  • Migrate to Swift 6 + Structured Concurrency
  • Migrate from Combine to AsyncSequence
  • Bump iOS, tvOS, and macOS versions to their latest versions
  • Create the GCOverseerProtocol for mocking/testing
  • Include DualSense support
    • GCOverseerProtocol.dualSenseControllers()
      • Returns all DualSense controllers that are connected to the device.

swift-version swift-package-manager platform ci-status license

GCOverseer 🎮

AsyncSequence wrapper around Apple's Game Controller Framework.

Tested Platforms

  • iOS 18.1.1
  • macOS 15.1.1 (Sequoia)
  • Mac Catalyst 18.1.1
  • tvOS 18.1
  • Xcode 16.1
  • Swift 6.0.2

Usage Examples

Handle Controller Connection/Disconnection Events

import SpriteKit
import GCOverseer

class GameScene: SKScene {

    let gcOverseer = GCOverseer()

    override init(size: CGSize) {
        super.init(size: size)

        // 🎮 Handle game controller connection/disconnection asynchronously
        Task {
            for await controllerEvent in gcOverseer.connectionStream {
                switch controllerEvent {
                case .connected:
                    print("A game controller connected.")
                case .disconnected:
                    print("A game controller disconnected.")
                }
            }
        }
    }
}

Available Properties

Property Description
var connectionStream: AsyncStream<GameControllerEvent> Provides an AsyncSequence for observing connect/disconnect events of game controllers.

Available APIs

API Description
controllers Returns all controllers connected to the device. E.g. DualShock, Xbox, Siri Remote controllers, etc.
extendedGamepadControllers() Returns all controllers supporting the extendedGamepad profile connected to the device. E.g., DualShock, Xbox controllers, etc.
dualShockControllers() Returns all DualShock controllers that are connected to the device.
dualSenseControllers() Returns all DualSense controllers that are connected to the device.
xboxControllers() Returns all Xbox controllers that are connected to the device.
microGamepadControllers() Returns all controllers supporting the microGamepad profile connected to the device. E.g. Apple's Siri Remote.
motionControllers() Returns all controllers supporting the motion profile connected to the device.
controllerFor(playerIndex:) Returns the controller for the player 1, player 2, etc.
enableLogging() / disableLogging() Enables/disables logging output.

Integration

Xcode

Use Xcode's built-in support for SPM.

or...

Package.swift

In your Package.swift, add GCOverseer as a dependency:

dependencies: [
    .package(
        url: "https://github.com/backslash-f/gcoverseer",
        .upToNextMajor(from: "2.0.0")
    )
]

Associate the dependency with your target:

targets: [
    .target(
        name: "YourTargetName",
        dependencies: [
            .product(
                name: "GCOverseer",
                package: "gcoverseer"
            )
        ]
    )
]

Run: swift build

Description

  • Swift Tools 6.0.0
View More Packages from this Author

Dependencies

Last updated: Sun May 11 2025 22:54:30 GMT-0900 (Hawaii-Aleutian Daylight Time)