ExtensionKit
developer.apple.com
developer.apple.com
The code editor Chime just released extension support in their 2.0 release if you are on macOS 13. They have a lot of good details on how the implemented the feature on their blog. https://www.chimehq.com/blog/extensionkit-intro
Having been (a minor) part of the Firefox effort, that was a real pain to implement, so sounds like a very useful component.
It's nice when extensions don't crash the host application, but the mitigations aren't free. It's interesting that Swift's stable ABI will drastically lower that cost, since you usually need some kind of serialization (although people have been using mmap to share data between host/extension process for awhile too to avoid the serialization penalty)
For example extensions on macOS, go to system preferences and search for extensions. They're listed by affording context (e.g., Finder, Photos Editing). Mine include pdf conversion, cropping photos, etc. You can create your own via Automator.
The docs imply that before Ventura (13.0), developers had to create a property list to declare NSExtension, but now you can do it in Swift. However, the TextTransformer sample has the usual melange of metadata, and there's no deployment information in the API documentation.
Ideally, a simple swift script would be sufficient :)
Apple has offered App Extensions for several years, in both UI-serving and non-UI contexts. App extensions are secondary services, bundled within apps, to provide some service. These extensions are invoked in their own process space, typically in the containing application's sandbox.
Examples include:
- The contents of the action/share menu in apps, which for example lets you share photos onto social media
- Audio Units
- Photo plugins
- Password manager autofill
- Content blockers
- Custom keyboards
- Filesystem providers to have a cloud storage show up in the Files app
- Finder synchronization for cloud-synchronized services like OneDrive
- All app integrations to extend Siri
ExtensionKit (and the underlying ExtensionFoundation) lets a host application define its own extension points, which other applications can provide. I do not believe you can define n-to-m extensions with this interface however; I can create a language server for an iOS text editor and put it in an app, but I can't do that once and support _every_ text editor.
Christ
This misses opportunities to reach developers-- and the tech is actually really compelling. I'm experimenting with it in the BoldContacts app, which conceptually extends the Contacts app to give disabled people ways to contact their families and caregivers.
Apple's documentation group needs a new leader ASAP who can emphasize documentation usability in concert with real-world developers. Apple wants its platform to continue being successful, and this goal can be helped by a documentation team that creates examples, questions-and-answers, and tutorials.
Apple’s API documentation is nearly useless because it usually doesn’t give me any info that I can’t already infer from my IDE (which of course is XCode, sigh).
I usually don’t need a list of classes and methods, I need to know how the pieces fit together to do something useful.
They say a picture is worth a thousand words. Well, an example is worth a thousand method signatures.
Is this because programming that targets poorly documented APIs is taught at select universities, and Apple wishes for these new grads to have an upper hand?
If you ask questions on the developer.apple.com forums, Apple engineers often answer them directly. At least that has been my experience.
CoreFoo is going to be a low level library for dealing with Foo. FooKit is going to be a high level way to create gui apps that deal with Foo. Likely FooKit uses CoreFoo under the hood.
ExtensionKit allows you to expose realtime UI or information, coming from an installed app instead of a 3rd party service.
That way you don't have to expose your API or build an SDK. You just have functions in your app that can be invoked.
Also the feature is only provided if the user has that app installed. So the experience is curated.
Nope. You can decide how and where to load and call entirely at runtime. Check out manpages for dlopen, dlsym.
I don't know anything about this new feature of Apple's, but knowing the way they've been going for the last decade and change I would guess the unique thing is around sandboxing, out of process calls, etc.
Such APIs have been around since the 90s, if not earlier. MS OLE, OpenDoc, Classic Mac's "Publish and Subscribe" API, I'm pretty sure OpenStep had something similar (which would be Apple's IP today, and predates Android by half a millenium).
This is really, really basic stuff. Why don't we have this capability?
So I think it'd have to be an app-review policy, and I suspect they'd have a LOT of pushback if they tried to enforce something like that.
They could have structured the OS so that each transition to a new view was a request to the operating system to open a URL, and the OS handled the routing to the browser, this app, a different app - but without that kind of a structure I don't think this very doable.
In some cases apps use the browser to render the app's UX, via hooks added to the browser to invoke native code (e.g. to expose native platform functionality that is not web accessible). This web content may only exist within the app sandbox's filesystem, or may be externally hosted.
But from a systems API standpoint, this is no different from Facebook opening links in their own internal browser so they can glean metrics on what links you are following.
So what you are talking about is actually a store policy (e.g. apps without the browser entitlement must open third-party web content via this other mechanism).
> and to force links to certain URLs to open in the app of my choosing, not Safari (in that case).
For HTTPS in general, IIRC the user can select from a list of apps with the browser entitlement.
Apps can already opt into their own HTTPS URL support for several years via Universal Links - but they have to get the domain owner to allow it to prevent abuse. They've been able to take over URI schemes outside of a reserved list since the App Store launched.
The android equivalent system (App Links IIRC) allows non-affiliated apps to take over certain HTTPS URL function, but the user has to enable it in settings - and will get a chooser if multiple applications can support the interface.
It's fundamentally a worse experience than it is on Android, in every way.
This framework is cross-platform, so it would offer such a plugin architecture on both macOS and iOS.
There's no hints that Apple would offer this kind of integration within their own apps however.
If not, what IPC is this using behind the hood ?
I don't know if it's because they actually hate developers, or they're just bad developers themselves.
---
More on topic, this is an interesting approach to a tricky problem that exploits one of Swift's strengths (a stable ABI) and Apple's tight integration across the system (standardized app installation/structure/store/etc). You expose some functions as an extension/plugin API and other apps can just call them. Neat! IPC kind of sucks!
What could use some more discussion is how if you have two apps running and calling eachother (or being called from eachother), how does that affect the threading model? Are calls scheduled to happen later on the main UI thread, or are they actually coming from a separate process and you need to worry about synchronization if that call affects any kind of state?
External developers have complained for years. [1]
[1]: https://www.caseyliss.com/2020/11/10/on-apples-pisspoor-docu...
I'm sorry to disappoint, but ExtensionKit/Foundation do not make use of any Swift features in the way you describe. It's all just IPC (via XPC), so much of it is useable from ObjC, or even C!
Also, this does not provide a direct app-to-app communication channel. The extensions themselves must be separate executables and run within their own sandbox. I think the extension could communication with its containing app, but the system is not set up to do that. All your scheduling questions are really around how XPC works. The view itself is basically an image within your hosting app, so communication is entirely async to the other process.
and on iOS, the containing app is likely not running (in a GUI context).
Typically, the extension is its own small program bundled within the app. The app can be run by an end user, while the extension can only be invoked via the extension mechanism.
I'm more interested in the extension handling after that IPC layer, it's usually non trivial to integrate the call into an existing app's threading model.
This fact has been reported multiple times before[1][2][3], and it's frustrating that a company that claims having over 1000 engineers, and touts its $6B campus at every opportunity in every one of its keynotes has, evidently, not enough resources for proper documentation.
[1]https://news.ycombinator.com/item?id=33411242 [2]https://news.ycombinator.com/item?id=33410300 [3]https://news.ycombinator.com/item?id=33410329
Those two things are completely orthogonal tho... an API/tool/service can even be used to build billion dollar businesses and not have proper documentation...
That seems like a really good reason not to post it again as a toplevel comment.
https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que...
But I still feel that, as paying developers (membership fees, and giving out 15-30% of sales to Apple), we should get all the basic info needed without relying on third parties to get it.
Also is it really COM like? it doesn't look like it
EDIT:
So it isn't the C++ object model per se.
Especially once you crossed over into Office/VB land, and everything was just IDispatch, Variants, BSTRs and SafeArrays.