Sample Code

View sample code referenced in the WWDC21 session videos.

Accessibility
  • Create Accessible Experiences for watchOS

    Learn how to make your watchOS app more accessible.

    iOS watchOS

    View code
  • Creating Accessible Views

    Make your app accessible to everyone by applying accessibility modifiers to your SwiftUI views.

    iOS macOS

    View code
  • WWDC21 Challenge: Large Text Challenge

    Design for large text sizes by modifying the user interface.

    iOS

    View code
  • WWDC21 Challenge: Speech Synthesizer Simulator

    Simulate a conversation using speech synthesis.

    iOS

    View code
  • WWDC21 Challenge: VoiceOver Maze

    Navigate to the end of a dark maze using VoiceOver as your guide.

    iOS

    View code
Audio & Video
  • Applying Biquadratic Filters to a Music Loop

    Change the frequency response of an audio signal using a cascaded biquadratic filter.

    macOS

    View code
  • Building a Custom Catalog and Matching Audio

    Display lesson content that’s synchronized to a learning video by matching the audio to a custom reference signature and associated metadata.

    iOS

    View code
  • Creating an Audio Device Driver

    Create a configurable audio input source as a driver extension that runs in user space.

    macOS DriverKit

    View code
  • Creating an Audio Server Driver Plug-in

    Build a virtual audio device by creating a custom driver plug-in.

    macOS

    View code
  • Playing Video Content in a Standard User Interface

    Play media fullscreen, embedded inline, or in a floating picture-in-picture window using a player view controller.

    iOS Mac Catalyst

    View code
  • Supporting Coordinated Media Playback

    Create synchronized media experiences that enable users to watch and listen across devices.

    iOS

    View code
  • Working with Overlays and Parental Controls in tvOS

    Add interactive overlays, parental controls, and livestream channel flipping using a player view controller.

    tvOS

    View code
App Services
  • Booking Rides with SiriKit

    Add Intents extensions to your app to handle requests to book rides using Siri and Maps.

    iOS

    View code
  • Build Mail App Extensions

    Create app extensions that block content, perform message and composing actions, and help message security.

    macOS

    View code
  • Delivering Rich App Experiences with Haptics

    Enhance your app’s experience by incorporating haptic and sound feedback into key interactive moments.

    iOS

    View code
  • Implementing a Store In Your App Using the StoreKit API

    Offer in-app purchases and manage entitlements using signed transactions and status information.

    iOS

    View code
  • Implementing Proximity-Based Interactions Between Devices

    Learn how to interact with a nearby device by measuring the distance between a watch and a paired iPhone.

    iOS watchOS

    View code
  • Implementing Spatial Interactions with Third-Party Accessories

    Establish a connection with a nearby accessory to begin periodically receiving its distance from the user’s device.

    iOS

    View code
  • Loading and Displaying a Large Data Feed

    Consume data in the background, and lower memory use by batching imports and preventing duplicate records.

    iOS macOS

    View code
  • Offering Apple Pay in Your App

    Collect payments with iPhone and Apple Watch using Apple Pay.

    iOS watchOS

    View code
  • Providing Hands-Free App Control with Intents

    Resolve, confirm, and handle intents without an extension.

    iOS Mac Catalyst

    View code
  • Soup Chef: Accelerating App Interactions with Shortcuts

    Make it easy for people to use Siri with your app by providing shortcuts to your app’s actions.

    iOS Mac Catalyst watchOS

    View code
  • Using MusicKit to Integrate with Apple Music

    Find an album in Apple Music that corresponds to a CD in a user’s collection, and present the information associated with the album.

    iOS

    View code
Augmented Reality
  • Building an Immersive Experience with RealityKit

    Use systems and postprocessing effects to create a realistic underwater scene.

    iOS

    View code
  • Creating a Photogrammetry Command-Line App

    Generate 3D objects from images using RealityKit Object Capture.

    macOS

    View code
  • Taking Pictures for 3D Object Capture

    Capture high-quality images with depth and gravity data to use with RealityKit Object Capture.

    iOS

    View code
  • Tracking Geographic Locations in AR

    Track specific geographic areas of interest and render them in an AR experience.

    iOS

    View code
  • WWDC21 Challenge: Framework Freestyle

    Create an AR experience that randomly selects a programming framework and maps it onto the user’s face.

    iOS

    View code
Business and Distribution
  • Displaying an Indoor Map

    Use the Indoor Mapping Data Format (IMDF) to show an indoor map with custom overlays and points of interest.

    iOS

    View code
Developer Tools
  • SlothCreator: Building DocC Documentation in Xcode

    Build DocC documentation for a Swift package that contains a DocC Catalog.

    View code
Graphics & Games
  • Adding Recurring Leaderboards to Your Game

    Encourage competition in your games by adding leaderboards that have a duration and repeat.

    iOS

    View code
  • Control the Ray Tracing Process Using Intersection Queries

    Explicitly enumerate a ray’s intersections with acceleration structures by creating an intersection query object.

    iOS macOS

    View code
  • Creating a Game with SceneUnderstanding

    Create AR games and experiences that interact with real-world objects on LiDAR-equipped iOS devices.

    iOS

    View code
  • Processing HDR Images with Metal

    Implement a post-processing pipeline using the latest features on Apple GPUs.

    iOS macOS tvOS

    View code
  • Recording and Streaming Your macOS App

    Share screen recordings, or broadcast live audio and video of your app, by adding ReplayKit to your macOS apps and games.

    macOS

    View code
  • Rendering Reflections in Real Time Using Ray-Tracing

    Render realistic real-time lighting by dynamically generating reflection maps using a ray-tracing compute pass.

    macOS

    View code
  • Supporting Game Controllers

    Add a virtual controller to your game that is an onscreen software emulation of a physical controller.

    iOS macOS tvOS

    View code
Health & Fitness
  • Accessing Data from a SMART Health Card

    Query for and validate a verifiable clinical record.

    iOS

    View code
  • Build a Workout App for Apple Watch

    Create your own workout app, quickly and easily, with HealthKit and SwiftUI.

    iOS watchOS

    View code
ML & Vision
  • Applying Matte Effects to People in Images and Video

    Generate image masks for people automatically by using semantic person-segmentation.

    iOS

    View code
  • Classifying Live Audio Input with a Built-in Sound Classifier

    Detect and identify hundreds of sounds by using a trained classifier.

    iOS Mac Catalyst

    View code
  • Locating and Displaying Recognized Text

    Configure and perform text recognition on images to identify their textual content.

    macOS

    View code
Photos & Camera
  • AVCam: Building a Camera App

    Capture photos with depth data and record video using the front and rear iPhone and iPad cameras.

    iOS

    View code
  • AVCamBarcode: Detecting Barcodes and Faces

    Identify machine readable codes or faces by using the camera.

    iOS

    View code
  • Selecting Photos and Videos in iOS

    Improve the user experience of finding and selecting assets by using the Photos picker.

    iOS

    View code
Privacy & Security
  • Connecting to a Service with Passkeys

    Allow users to sign in to a service without typing a password.

    iOS Mac Catalyst

    View code
  • Simplifying User Authentication in a tvOS App

    Build a fluid sign-in experience for your tvOS apps using AuthenticationServices.

    tvOS

    View code
Safari & Web
  • Adopting Declarative Content Blocking in Safari Web Extensions

    Block web content with your web extension using the declarative net request API.

    iOS macOS

    View code
  • Adopting New Safari Web Extension APIs

    Improve your web extension in Safari with a non-persistent background page and new tab-override customization.

    iOS macOS

    View code
Swift
  • Updating an App to Use Swift Concurrency

    Improve your app’s performance by refactoring your code to take advantage of asynchronous functions in Swift.

    iOS watchOS

    View code
SwiftUI & UI Frameworks
  • Add Rich Graphics to Your SwiftUI App

    Make your apps stand out by adding background materials, vibrancy, custom graphics, and animations.

    iOS macOS

    View code
  • Adjust Your Layout with Keyboard Layout Guide

    Dynamically respond to keyboard movement by using the tracking features of the keyboard layout guide.

    iOS

    View code
  • Adopting Drag and Drop in a Table View

    Demonstrates how to enable and implement drag and drop for a table view.

    iOS

    View code
  • Building High-Performance Lists and Collection Views

    Improve the performance of lists and collections in your app with prefetching and image preparation.

    iOS

    View code
  • Building a Great Mac App with SwiftUI

    Create engaging SwiftUI Mac apps by incorporating side bars, tables, toolbars, and several other popular user interface elements.

    macOS

    View code
  • Building and Improving Your App with Mac Catalyst

    Improve your iPadOS app with Mac Catalyst by supporting native controls, multiple windows, sharing, printing, menus and keyboard shortcuts.

    iOS Mac Catalyst

    View code
  • Customize and Resize Sheets in UIKit

    Discover how to customize sheets in UIKit.

    iOS

    View code
  • Fruta: Building a Feature-Rich App with SwiftUI

    Create a shared codebase to build a multiplatform app that offers widgets and an App Clip.

    iOS macOS

    View code
  • Navigating an App’s User Interface Using a Keyboard

    Navigate between user interface elements using a keyboard and focusable UI elements in iPad apps and apps built with Mac Catalyst.

    iOS Mac Catalyst

    View code
  • Organize Your User Interface with a Stack View

    Group individual views in your app’s user interface into a scrollable stack view.

    macOS

    View code
  • Restoring Your App’s State

    Provide continuity for the user by preserving current activities.

    iOS

    View code
  • Using Suggested Searches with a Search Controller

    Create a search interface with a table view of suggested searches.

    iOS

    View code
  • Using TextKit 2 to Interact with Text

    Interact with text by managing text selection and inserting custom text elements.

    macOS

    View code
System Services
  • Connecting a Network Driver

    Create an Ethernet driver that interfaces with the system’s network protocol stack.

    macOS DriverKit

    View code
  • Displaying Human-Friendly Content

    Convert data into readable strings or Swift objects using formatters.

    iOS macOS

    View code
  • Encrypting and Decrypting a Single File

    Encrypt a single file and save the result to the file system, then decrypt and recreate the original file from the archive file using Apple Encrypted Archive.

    macOS

    View code
  • Encrypting and Decrypting a String

    Encrypt the contents of a string and save the result to the file system, then decrypt and recreate the string from the archive file using Apple Encrypted Archive.

    macOS

    View code
  • Encrypting and Decrypting Directories

    Compress and encrypt the contents of an entire directory or decompress and decrypt an archived directory using Apple Encrypted Archive.

    macOS

    View code
  • Implementing Interactions Between Users in Close Proximity

    Enable devices to access relative positioning information.

    iOS

    View code
  • Interacting with Bluetooth Peripherals During Background App Refresh

    Keep your complications up-to-date by reading values from a Bluetooth peripheral while your app is running in the background.

    iOS watchOS

    View code
  • Receiving Voice and Text Communications on a Local Network

    Provide voice and text communication on a local network isolated from Apple Push Notification service by adopting Local Push Connectivity.

    iOS macOS

    View code
  • Sharing CloudKit Data with Other iCloud Users

    Create and share private CloudKit data with other users by implementing the sharing UI.

    iOS Mac Catalyst

    View code
  • Sharing Your Location to Find a Park

    Ask for location access using a customizable location button.

    iOS

    View code
  • Showcase App Data in Spotlight

    ​Index app data so users can find it by using Spotlight search. ​​

    iOS Mac Catalyst

    View code
  • Synchronizing a Local Store to the Cloud

    Share data between a user’s devices and other iCloud users.

    iOS Mac Catalyst

    View code
  • Syncing Files on macOS

    Create an extension to sync files to the cloud.

    macOS

    View code