SwiftyXPC - a wrapper for Apple’s XPC interprocess communication library that gives it an easy-to-use, idiomatic Swift interface.

Overview

SwiftyXPC

Hmm, what’s this?

SwiftyXPC is a wrapper for Apple’s XPC interprocess communication library that gives it an easy-to-use, idiomatic Swift interface.

But there’s already NSXPCConnection!

Well, yes, but with its protocol-and-proxy-based interface, it’s far better suited to Objective-C than Swift. Using NSXPCConnection from Swift has always felt somewhat awkward, and with the advent of Swift Concurrency, it’s even worse, given that everything has to be wrapped in withCheckedThrowingContinuation blocks. NSXPCConnection has also tended to be behind libxpc in certain important ways—notably, in the ability to verify the code signature of a remote process via an audit token.

By contrast, SwiftyXPC:

  • Offers a fully Swift Concurrency-aware interface. Use try and await to call your helper code with no closures necessary.
  • Gives you a straightforward interface for your helper functions; take an argument, return a value async. No fussing around with Objective-C selectors and reply blocks.
  • Built around the Codable protocol, so you can use any types you want for the argument and return value, as long as both types conform to Codable, and it Just Works™. Error types are preserved as well, if they are Codable and you register their domains with the shared XPCErrorRegistry object.
  • Only links against XPC and Security (the latter for the code signature validation), so there’s no need to link Foundation into your app, deal with Objective-C bridging magic, or involve the Objective-C runtime at all (excluding any places where XPC or the Security framework may be using it internally).

But I want to support older macOS versions! Using Swift Concurrency means that it requires macOS 12!

Actually, it turns out that’s not true anymore! With Xcode 13.2, Swift concurrency now works all the way back to macOS 10.15 “Catalina”, and consequently, so does this library.

What’s the license on this?

MIT.

You might also like...
☎️ NextcloudKit Apple library

NextcloudKit Installation Carthage Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary framework

Powerful property wrapper to back codable properties.

BackedCodable Powerful property wrapper to back codable properties. Why Swift's Codable is a great language feature but easily becomes verbose and req

A property wrapper to enforce that closures are called exactly once!

A property wrapper that allows you to enforce that a closure is called exactly once. This is especially useful after the introduction of SE-0293 which makes it legal to place property wrappers on function and closure parameters.

ExtraLottie is a SwiftUI wrapper of Lottie-iOS

📝 What is ExtraLottie? ExtraLottie is a SwiftUI wrapper of Lottie-iOS. ℹ️ Info Currently ExtraLottie supports custom loop mode, LottieLoopMode, start

A collection of Swift Tutorials built with Apple's DocC.

Swift Tutorials This is not a package, it's just a bunch of tutorials This project uses Apple's DocC (Documentation Compiler) to create a set of Swift

The QuoteKit is a Swift framework to use the free APIs provided by Quotable created by Luke Peavey.
The QuoteKit is a Swift framework to use the free APIs provided by Quotable created by Luke Peavey.

QuoteKit The QuoteKit is a Swift framework to use the free APIs provided by Quotable created by Luke Peavey. It uses the latest async/await syntax for

How to use swiftlint to identify unused code or unused imports in a Swift codebase

Swift compilation database This repository demonstrates how to use swiftlint to identify unused code or unused imports in a Swift codebase. How to run

Sonic language: Heavily inspired by Swift, but compiles to C so you can use it anywhere.
Sonic language: Heavily inspired by Swift, but compiles to C so you can use it anywhere.

Sonic Sonic programming language: Heavily inspired by Swift, but compiles to C so you can use it anywhere. Brought to you by Chris Hulbert and Andres

A sample app demonstrates how to use Atlantis on Swift Playground (iOS/macOS)
A sample app demonstrates how to use Atlantis on Swift Playground (iOS/macOS)

Atlantis with Swift Playground A sample app demonstrates how to use Atlantis on

Comments
  • How to work with `FileDescriptor`?

    How to work with `FileDescriptor`?

    FIrst of all, this framework is awesome! Apple should adopt the library as the official SDK (so they can also fixing the non type safe interface currently we are using).

    I'm wondering what is the correct way to handle FileDescriptor.

    The problem is, the current API only allows us to return a response, where the fd is not sent yet so we cannot close it immediately (or in defer). However, there is no way to know when the response is sent (or queued) so we cannot close the fd properly.

    If we are dealing with xpc_fd_create directly, then it is quite easy as it calls dup internally and managed the owned fd afterwards. I think we also need to do similar things using XPCFileDescriptor (even for 12.0+). XPCFileDescriptor should own the fd and close it after calling xpc_fd_create. User can still use FileDescriptor as long as they want to close the fd themselves.

    opened by zhuhaow 5
  • Example code snippet / question

    Example code snippet / question

    Thanks a ton for your work on this. From what I've been able to understand, this looks like a massive improvement on doing this via the NSXPCConnection route.


    What exactly would a simple XPC Service/client (macOS application) look like?

    Right now I have the main.swift file within an XPC Service project within the macOS app. What would be the best/most appropriate way to structure the service there that (for example) accepts a string from a client and returns it capitalized via its response?

    On the client side, what I imagine it would look like is that you'd setup the connection (in a struct?) and then activate the connection in applicationDidFinishLaunching within the AppDelegate but I'm not sure and was hoping to get some guidance on that.

    opened by capaldo 2
Owner
null
This is a Swift Package bundling different Train APIs into one simple Swift interface.

This is a Swift Package bundling different Train APIs into one simple Swift interface.

ICE Buddy 8 Jul 5, 2022
A react native interface for integrating payments using Braintree

A react native interface for integrating payments using Braintree

eKreative 15 Sep 7, 2022
The Git interface you've been missing all your life has finally arrived.

GitUp Work quickly, safely, and without headaches. The Git interface you've been missing all your life has finally arrived. Git recently celebrated it

GitUp 10.5k Sep 22, 2022
Runtime Mobile Security (RMS) 📱🔥 - is a powerful web interface that helps you to manipulate Android and iOS Apps at Runtime

Runtime Mobile Security (RMS) ?? ?? by @mobilesecurity_ Runtime Mobile Security (RMS), powered by FRIDA, is a powerful web interface that helps you to

Mobile Security 1.9k Sep 16, 2022
Are you sure the chemical compounds of your daily use are 100% safe? Use Chem-Aware, identify them right now!

View Project On Devpost: Built With: PubChem's REST API How To Install Chem Aware: Prerequiste: Latest Version of Xcode and Simulators installed The a

Jerry Zhang 5 Aug 23, 2022
Easy-to-use segues in SwiftUI, allowing for presenting views using common UIKIt Segue types - push, modal and popover

Easy-to-use segues in SwiftUI, allowing for presenting views using common UIKIt Segue types - push, modal and popover

Gordan Glavaš 5 Apr 16, 2022
A Swift cross-platform (Apple and Linux) networking library.

KippleNetworking A Swift library that offers cross-platform (Apple and Linux) networking support, intended for the creation of cross-platform SDKs to

Kipple 11 Sep 20, 2022
A Swift wrapper around the CoreSymbolication private framework on macOS.

CoreSymbolication provides a very powerful system for looking up and extracting symbolic information from mach-o executables, dyld shared caches, and dSYMs.

Stacksift 6 Sep 2, 2022
A Swift wrapper around the JSONbin.io API

A Swift wrapper around the JSONbin.io API

Fleuronic 5 Dec 16, 2021
Apple SMC library & tool

SMCKit An Apple System Management Controller (SMC) library & command line tool in Swift for Intel based Macs. The library works by talking to the Appl

Omeed 407 Sep 9, 2022