Swift Academy · Lesson

App Extensions Overview

Understand share, action, and other extensions.

Lesson 3 of 413 steps

App Extensions Overview is a free Swift Academy lesson on CoddyKit. This is lesson 3 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, and your progress syncs across the web and the CoddyKit app. The Swift Academy course includes 4 lessons in total.

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"
_ = group

Share 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"
_ = share

Reading 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"
_ = action

Notification 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"
_ = service

Notification 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"
_ = content

The 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"
_ = point

Memory 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"
_ = limits

Sharing 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"
_ = shared

Quick 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 NSItemProvider and finish with completeRequest.
  • Each extension declares its NSExtensionPointIdentifier and runs under tight memory/time limits.
  • Share data through an App Group and reuse code via a shared package.
Free to start

Learn Swift with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
122
Lessons
409

Frequently Asked Questions

Is the “App Extensions Overview” lesson free?

Yes — any 3 lessons of the Swift Academy learning path, including “App Extensions Overview”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Swift Academy course includes 4 lessons in total.

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, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.

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

  1. Building a WidgetKit Widget
  2. Timeline Providers and Snapshots
  3. App Extensions Overview
  4. App Intents and Shortcuts
← Back to Swift Academy