Contents

Structuring Your Code to Support App Extensions

Move your back-end services to a private framework so your app and app extensions can use them.

Overview

An app extension is an agent that acts on behalf of your app, vending services or providing information to the system when asked. Because they extend your app’s behavior, app extensions often need access to the same back-end services and data that your app uses.

Lightweight extensions that don’t include most of your app’s code can respond to a user’s request more quickly. Long-running tasks like playing music or tracking a workout need to happen in your app. If necessary, you can resolve the parameters of an intent in an extension, then instruct SiriKit to launch your app for the final handling step.

If your app and app extension share services, consider structuring your code in the following way:

  • Implement your core services in a private shared framework. A private shared framework lets you place the code for accessing your services in one code module and use that code from multiple targets. Shared frameworks minimize the size of both executables and make testing easier by ensuring that each executable uses the same code path.

  • Use a shared container to store common resources. Put relevant images and data files into a shared container so your app and app extension can use them. You enable shared container support in the Capabilities tab of each target.

See Also

Articles