Swiftpack.co - Alkenso/sXPC as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Alkenso/sXPC
Use power of Swift to make NSXPCConnection type-bound
.package(url: "https://github.com/Alkenso/sXPC.git", from: "0.1.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"))
connection.resume()

let proxy = connection.remoteObjectProxy { error in
    print(error)
}

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

Setup listener

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

GitHub

link
Stars: 2
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

sXPC released!
25 weeks ago

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