App Extensions Overview
Understand share, action, and other extensions.
App Extensions Overview is a free Swift Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What App Extensions Are
An app extension lets your app provide functionality inside other apps or system surfaces — sharing content, custom keyboards, Spotlight indexing, and more. Each extension is a separate target with its own lifecycle, sandbox, and entry point defined by the system.
// Extensions run in their own process, launched
// by the host (Photos, Safari, Messages, the system),
// not by your main app.Host, Container, and Sandbox
Three players: the host app invokes the extension, your container app ships it, and the extension itself runs sandboxed. The extension cannot freely talk to your app — they communicate through an App Group, never direct memory access.
import Foundation
// Container app + Extension target share data via
// an App Group, e.g. group.com.example.app
let group = "group.com.example.app"
_ = groupShare Extensions
A Share Extension appears in the system share sheet, letting users send content (text, URLs, images) from any app into yours. It subclasses or hosts a view controller and reads the shared items from the extension context.
import Foundation
// Share extension reads incoming items:
// extensionContext?.inputItems
// each NSExtensionItem has attachments (NSItemProvider)
let share = "appears in the share sheet"
_ = shareReading Shared Items
Shared content arrives as NSItemProvider attachments. You check the type identifier and load the value asynchronously. This is how a share extension grabs the URL or image the user is sharing.
import UniformTypeIdentifiers
func handle(_ provider: NSItemProvider) {
if provider.hasItemConformingToTypeIdentifier(
UTType.url.identifier) {
provider.loadItem(
forTypeIdentifier: UTType.url.identifier) {
value, _ in
print("shared url:", value ?? "none")
}
}
}Action Extensions
An Action Extension transforms or views content in place — translate selected text, annotate a PDF — and can return a result to the host. Unlike a share extension, it is meant to act on content rather than send it elsewhere.
import Foundation
// Action extension may return modified items:
// extensionContext?.completeRequest(
// returningItems: outputItems)
let action = "acts on content, can return a result"
_ = actionNotification Service Extension
A Notification Service Extension intercepts incoming push notifications with mutable-content: 1 to modify them before display — decrypt the body, download a media attachment, or rewrite the title — within a short time budget.
import UserNotifications
// Override in UNNotificationServiceExtension:
// didReceive(_ request:, withContentHandler:)
// mutate bestAttemptContent, then call the handler
let service = "modifies push before it shows"
_ = serviceNotification Content Extension
A Notification Content Extension provides a custom UI for an expanded notification — a map, a media player, interactive controls — shown when the user long-presses the banner. It binds to a notification category.
import UserNotifications
// UNNotificationContentExtension renders a custom view
// for a given UNNotificationCategory when expanded.
let content = "custom expanded notification UI"
_ = contentThe completeRequest Lifecycle
Extensions are short-lived. When done, call extensionContext?.completeRequest(returningItems:completionHandler:) to signal completion and let the host dismiss you. To bail out, use cancelRequest(withError:). Holding the process open wastes resources and may be killed.
import Foundation
func finish(context: NSExtensionContext?) {
context?.completeRequest(
returningItems: [], completionHandler: nil)
}Other Extension Points
iOS offers many extension points: custom keyboards, document providers, Spotlight indexing, Safari content blockers, Siri intents, photo editing, and file provider extensions. Each conforms to a system-defined protocol declared by an NSExtensionPointIdentifier in its Info.plist.
// Info.plist of an extension declares its point:
// NSExtension > NSExtensionPointIdentifier
// e.g. com.apple.share-services
// com.apple.usernotifications.service
let point = "each extension declares its point"
_ = pointMemory and Time Limits
Extensions run under tighter limits than the main app — less memory and a short wall-clock budget. Do minimal work, avoid large allocations, and offload heavy processing to the main app via shared storage when possible.
import Foundation
// Tight memory + short runtime.
// Pattern: extension stages data in the App Group,
// the main app processes it fully on next launch.
let limits = "keep extensions lean and fast"
_ = limitsSharing Code Between Targets
To avoid duplicating logic, put shared models and helpers in a framework or Swift package both the app and extension depend on. Mark only what each target needs; the extension links the same code without copying it.
import Foundation
// Shared Swift package 'AppCore' linked by:
// - main app target
// - share extension target
// - widget extension target
let shared = "one source of truth for models"
_ = sharedQuick Check
Recall how an extension communicates with its container app.
Recap
You surveyed app extensions:
- Extensions are separate, sandboxed targets launched by a host; types include share, action, notification service, and notification content.
- Read incoming content via
NSItemProviderand finish withcompleteRequest. - Each extension declares its
NSExtensionPointIdentifierand runs under tight memory/time limits. - Share data through an App Group and reuse code via a shared package.
Frequently asked questions
Is the “App Extensions Overview” lesson free?
Yes — the full text of “App Extensions Overview” is free to read here on the web, and the Swift Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Swift Academy course, upgrade to CoddyKit PRO.
What will I learn in “App Extensions Overview”?
Understand share, action, and other extensions. You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Swift Academy?
No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “App Extensions Overview” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Swift Academy lesson?
Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Building a WidgetKit Widget
- Timeline Providers and Snapshots
- App Extensions Overview
- App Intents and Shortcuts