Swiftpack.co - Alkenso/sXPC as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Alkenso.
Alkenso/sXPC 0.2.0
Use power of Swift to make NSXPCConnection type-bound
⭐️ 10
🕓 6 days ago
.package(url: "https://github.com/Alkenso/sXPC.git", from: "0.2.0")

sXPC - Swift-typed wrapper around NSXPCConneciton.

sXPC allows you to

  • make NSXPCConnection to produce typed remoteObject / set typed exportedObject
  • pass Swift-only structs/enums over XPC connection (with very little additional code)
  • have NSXPCIntegrace description in the single place
  • hide objective-c details, using pure Swift in the App

Library family

You can also find Swift libraries for macOS / *OS development

  • SwiftConvenience: Swift common extensions and utilities used in everyday development
  • sLaunchctl: Swift API to register and manage daemons and user-agents
  • sMock: Swift unit-test mocking framework similar to gtest/gmock

XPC service example

Note: full sample code resides in Sample folder

Assume protocol you are going to use over XPC connection

public struct Request: Equatable, Codable {
    public var processUID: uid_t
    public var processPID: pid_t
    public var processPath: URL

public struct Response: Equatable, Codable {
    public var allow: Bool
    public var cache: Bool

public protocol Service {
    func perform(_ request: Request, reply: @escaping (Response) -> Void)

Create connection & call

let connection = CreateServiceXPCConnection(connection: NSXPCConnection(serviceName: "com.example.XPCService"))

let proxy = connection.remoteObjectProxy { error in

let request = Request(...)
proxy.perform(request) { response in print(response) }

Setup listener

let listener = CreateServiceXPCListener(listener: listener)
listener.newConnectionHandler = {
    $0.exportedObject = DummyService()
    return true


Stars: 10
Last commit: 6 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Introduce XPCTransport - Swift session-like wrapper around XPC
6 days ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics