Sample Code

View sample code to see how the latest Apple technologies are implemented.

Featured
  • Adopting Menus and UIActions in your User Interface

    Add menus to your user interface, with built-in button support and bar-button items, and create custom menu experiences.

    iOS

    View code
  • Building a Feature-Rich App for Sports Analysis

    Detect and classify human activity in real time using computer vision and machine learning.

    iOS

    View code
  • Building Widgets Using WidgetKit and SwiftUI

    Create widgets to show your app’s content on the Home screen, with custom intents for user-customizable settings.

    iOS Mac Catalyst

    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
Frameworks
  • Accessibility Design for Mac Catalyst

    Improve navigation in your app by using keyboard shortcuts and accessibility containers.

    iOS Mac Catalyst

    View code
  • Adding Hardware Keyboard Support to Your App

    Enhance interactions with your app by handling raw keyboard events, writing custom keyboard shortcuts, and working with gesture recognizers.

    iOS Mac Catalyst

    View code
  • Adding Shortcuts for Wind Down

    Reveal your app’s shortcuts inside the Health app.

    iOS

    View code
  • Asynchronously Loading Images into Table and Collection Views

    Store and fetch images asynchronously to make your app more responsive.

    iOS Mac Catalyst

    View code
  • Building a Custom Peer-to-Peer Protocol

    Use Bonjour and TLS to establish secure connections between devices, and define a protocol for sending messages to play a simple game of Tic-Tac-Toe.

    iOS

    View code
  • Building Custom Views in SwiftUI

    Create a custom view with data driven transitions and animations in SwiftUI.

    macOS

    View code
  • Creating a Mobility Health App

    Create a health app that allows a clinical care team to send and receive mobility data.

    iOS

    View code
  • Creating Accessible Views

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

    iOS macOS

    View code
  • Creating and Updating Complications

    Build complications that display current information from your app.

    iOS watchOS

    View code
  • Creating NFC Tags from Your iPhone

    Save data to tags, and interact with them using native tag protocols.

    iOS

    View code
  • Customizing Scribble with Interactions

    Enable writing on a non-text-input view by adding interactions.

    iOS

    View code
  • Detecting Hand Poses with Vision

    Create a virtual drawing app by using Vision’s capability to detect hand poses.

    iOS Mac Catalyst

    View code
  • Detecting Human Body Poses in an Image

    Locate people and the stance of their bodies by analyzing an image with a PoseNet model.

    iOS

    View code
  • Developing a Safari Web Extension

    Customize and enhance web pages by building a Safari web extension.

    macOS

    View code
  • Displaying Human-Friendly Content

    Convert data into readable strings or Swift objects using formatters.

    iOS macOS

    View code
  • Drawing with PencilKit

    Add expressive, low-latency drawing to your app using PencilKit.

    iOS

    View code
  • Enhancing Your iPad App with Pointer Interactions

    Provide a great user experience with pointing devices, by incorporating pointer content effects and shape customizations.

    iOS

    View code
  • Implementing Alert Push Notifications

    Add visible alert notifications to your app by using the UserNotifications framework.

    iOS

    View code
  • Implementing Background Push Notifications

    Add background notifications to your app by using the UserNotifications framework.

    iOS

    View code
  • Implementing Interactions Between Users in Close Proximity

    Enable an iPhone to measure the relative position of other iPhones.

    iOS

    View code
  • Implementing Modern Collection Views

    Bring compositional layouts to your app and simplify updates to and management of your user interface with diffable data sources.

    iOS macOS Mac Catalyst

    View code
  • Inspecting, Modifying, and Constructing PencilKit Drawings

    Score users’ ability to match PencilKit drawings generated from text, by accessing the strokes and points inside PencilKit drawings.

    iOS

    View code
  • Integrating Your App with Siri Event Suggestions

    Donate reservations and provide quick access to event details throughout the system.

    iOS Mac Catalyst

    View code
  • Loading and Displaying a Large Data Feed

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

    iOS macOS

    View code
  • Managing Audio with SiriKit

    Control audio playback and handle requests to add media using SiriKit Media Intents.

    iOS

    View code
  • Messaging a Web Extension’s Native App

    Communicate between your Safari web extension and its containing app.

    macOS

    View code
  • Monitoring System Events with Endpoint Security

    Receive notifications and authorization requests for sensitive operations by creating an Endpoint Security client for your app.

    macOS

    View code
  • Providing Hands-free App Control with Intents

    Resolve, confirm, and handle intents without an extension.

    iOS

    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
  • 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 watchOS

    View code
  • SpeedySloth: Creating a Workout

    Start, stop, and to save workouts on Apple Watch with the Workout Builder API.

    iOS watchOS

    View code
  • Supporting Multiple Users in Your tvOS App

    Store separate data for each user with the new Runs as Current User capability.

    tvOS

    View code
  • UIKit Catalog: Creating and Customizing Views and Controls

    Customize your app’s user interface with views and controls in UIKit.

    iOS Mac Catalyst

    View code
  • Visualizing a Point Cloud Using Scene Depth

    Place points in the real-world using the scene’s depth data to visualize the shape of the physical environment.

    iOS

    View code
Graphics and Games
  • Accelerating Ray Tracing Using Metal

    Implement ray-traced rendering using GPU-based parallel processing.

    iOS macOS

    View code
  • Adding Custom Functions to a Shader Graph

    Run your own graph functions on the GPU by building the function programmatically.

    iOS

    View code
  • Adjusting Saturation and Applying Tone Mapping

    Convert an RGB image to discrete luminance and chrominance channels, and apply color and contrast treatments.

    macOS

    View code
  • Blurring an Image

    Filter an image by convolving it with custom and high-speed kernels.

    iOS

    View code
  • Creating a Collaborative Session

    Enable nearby devices to share an AR experience by using a peer-to-peer multiuser strategy.

    iOS

    View code
  • Creating a Fog Effect Using Scene Depth

    Apply virtual fog to the physical environment.

    iOS

    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
  • Creating a Metal Dynamic Library

    Compile a library of shaders and write it to a file as a dynamically linked library.

    iOS macOS

    View code
  • Creating a Multiuser AR Experience

    Enable nearby devices to share an AR experience by using a host-guest multiuser strategy.

    iOS

    View code
  • Equalizing Audio with vDSP

    Shape audio output using discrete cosine transforms and biquadratic filters.

    iOS

    View code
  • Finding the Sharpest Image in a Sequence of Captured Images

    Share image data between vDSP and vImage to compute the sharpest image from a bracketed photo sequence.

    iOS

    View code
  • SwiftShot: Creating a Game for Augmented Reality

    See how Apple built the featured demo for WWDC18, and get tips for making your own multiplayer games using ARKit, SceneKit, and Swift.

    iOS

    View code
  • Tracking Geographic Locations in AR

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

    iOS

    View code
Media
  • Adopting Picture in Picture Playback in tvOS

    Add advanced multitasking capabilities to your video apps by using Picture in Picture playback in tvOS.

    iOS tvOS

    View code
  • Capturing Stereo Audio from Built-In Microphones

    Configure an iOS device’s built-in microphones to add stereo recording capabilities to your app.

    iOS

    View code
  • Creating a Slideshow Project Extension for Photos

    Augment the macOS Photos app with extensions that support project creation.

    macOS

    View code
  • Editing and Playing HDR Video

    Support high-dynamic-range (HDR) video content in your app by using the HDR editing and playback capabilities of AVFoundation.

    iOS macOS

    View code
  • Playing Haptics on Game Controllers

    Add haptic feedback to supported game controllers by using Core Haptics.

    iOS

    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
  • Selecting Photos and Videos in iOS

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

    iOS

    View code
  • Writing Fragmented MPEG-4 Files for HTTP Live Streaming

    Create an HTTP Live Streaming presentation by turning a movie file into a sequence of fragmented MPEG-4 files.

    macOS

    View code
Developer Tools
  • Autosizing Views for Localization in iOS

    Add auto layout constraints to your app to achieve localizable views.

    iOS

    View code
  • Autosizing Views for Localization in macOS

    Add auto layout constraints to your app to achieve localizable views.

    macOS

    View code
App Store and Distribution
  • Determining Service Entitlement Using Node.js

    Determine a customer’s entitlement to your service, offers, and messaging by analyzing a validated receipt and the state of their subscription.

    View code