DevPrep

All topics › IDEs & SDK

App Extensions and App Groups: how does an extension share data with the app?

Middle PRO

The gist

An App Extension (widget, Share, Notification Service, keyboard, App Intents) is a separate .appex bundle inside the app that runs in its own process and is usually launched by the system or another app, not by yours. It has its own sandbox, its own data container and a strict memory limit (noticeably lower than the app's for widgets and the Notification Service Extension). That is why the main app's Documents is not accessible to the extension.

Shared data lives in an App Group: the capability is enabled in both targets with the same identifier (group.com.example.app), and both processes get a shared file container, shared UserDefaults and, if configured, a shared Keychain.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store