WWDC Quick Look đź’“ By SwiftGGTeam
Platforms State of the Union

Platforms State of the Union

Watch original video

Highlight

Apple launches Swift macros, SwiftData, interactive widgets, and the new visionOS platform in 2023, and increases link speeds up to 5x in Xcode 15.

Core Content

Every year WWDC’s Platforms State of the Union is the anchor point for developers to judge the direction of technology trends. The 2023 speech was hosted by Darin Adler, with six engineering leaders taking turns to take the stage, covering five levels: language, framework, tool, hardware and new platform.

(04:03) Holly Borla first introduced the macro system of Swift 5.9. Macros are compile-time annotations that generate new code based on the code structure. one#URLThe macro can check whether the URL string is legal during compilation. If it contains spaces, it will directly report an error and give repair suggestions. Attached macros are more powerful - add@AddAsync, the async/await version can be automatically generated without having to write the second function by hand. Macros are fully expandable, debuggable, and breakpointable in Xcode, no black box.

(09:30) Josh Shaffer takes over the baton to talk about SwiftUI. The focus this year is animation - gesture speed can be automatically transferred to the animation. The default animation is changed to spring-based physical movement. Just configure the duration and bounce parameters. SF Symbols also supports animation effects. More complex multi-stage animations can be created using the newAnimationPhaseAPI implementation. In terms of data flow,@ObservableMacro replacesObservableObject + @PublishedIn combination, all public properties are automatically published, and SwiftUI tracks access at field granularity, and unused field changes will not trigger view redrawing.

(15:53) SwiftData is this year’s big new framework. It’s based on Core Data’s persistence layer, but the API is completely redesigned for Swift. Add to class@ModelMacro, you will automatically get persistence, iCloud synchronization, undo and redo and other functions. Properties can be marked with additional annotations for uniqueness constraints. SwiftData natively supports Codable’s struct and enum, and complex structured data can also be queried efficiently. Integration with SwiftUI only requires adding a modifier to the root view to set the container, using@QueryJust read the data. Widgets can also directly access data in the same container.

(19:22) Jonathan Thomassian introduces new capabilities in WidgetKit, App Intents, TipKit, and AirDrop. iOS 17 widgets support interaction - buttons and toggle can respond directly in the widget, triggered by App Intent. Widgets can be displayed in StandBy mode, iPad lock screen, and macOS desktop, and the same SwiftUI code can be reused across platforms. TipKit provides system-level function guidance templates that can be intelligently displayed contextually to avoid repeatedly disturbing users.

(27:26) Brandon Corey brings game and camera updates. macOS Sonoma adds Game Mode, which prioritizes CPU and GPU resources for games. Game Porting Toolkit provides a three-step solution: first use a simulation environment to evaluate the performance potential of Windows games on Mac, then use Metal Shader Converter to automatically convert HLSL to Metal, and finally optimize the graphics code. On the camera side, Zero Shutter Lag, overlapping capture and delay processing triple the continuous shooting speed. HDR photos have obtained the ISO international standard, and iOS/iPadOS/macOS all provide APIs for displaying HDR-compatible photos.

(34:40) Lori Hylan-Cho shows off watchOS 10 design innovations. SwiftUI is the core of this system-level redesign - Vertical TabView supports variable page sizes, the containerBackground modifier uses gradient filling to improve readability, and NavigationSplitView directly reuses cross-platform code. The ToolbarItem in the Corner position allows the time to be automatically centered. All major UI components have updated material handling to automatically adapt to hardware size.

(39:41) Chris explains new developments in accessibility and privacy. For users who are sensitive to animation and flashing lights, the system has added two new APIs: Pause Animated Images and Dim Flashing Lights. The former stops GIF animations, and the latter automatically darkens flashing sequences in videos, and the algorithm has been open sourced. visionOS has dozens of accessibility features built in from day one, including eye control, voice control, head pointers and other alternative input methods.

(52:42) Ken Orr summarizes the Xcode 15 improvements. Code completion leverages context to prioritize the most relevant suggestions. Resource directories automatically generate symbols, providing type safety. SwiftUI preview supports all UI frameworks (SwiftUI, UIKit, AppKit) and allows you to switch platforms and devices directly in the canvas. Git staging functionality is integrated into the editor. Test reports are completely redesigned and include Top Insights, heat maps, timelines, and video recordings. Link speeds are increased by up to 5 times, and debug binary size is reduced by 30%. The Xcode App Store is 50% smaller and the simulator is downloadable on demand.

(01:00:56) Mike Rockwell introduced visionOS in the finale. Apps launch into Shared Space by default, existing alongside other apps. Three elements can be used: Window (flat window), Volume (3D container) and Full Space (full immersion space). SwiftUI extends depth support and ZStack can be layered in three-dimensional space with z-offset. RealityKit automatically adapts to ambient lighting, casts shadows, and uses dynamic foveation rendering to reduce edge rendering overhead. ARKit provides plane estimation, scene reconstruction, image anchoring, and world tracking. Persona and Spatial Persona allow users on FaceTime calls to appear in three dimensions, and SharePlay can synchronize physical movements.

Detailed Content

The actual form of Swift macros

Macros come in two forms. For independent macros (Freestanding)#Prefix:

let url = #URL("https://developer.apple.com")

Used for attached macros (Attached)@Prefix, directly transform the existing statement:

@AddAsync
func fetchContent(completion: @escaping (Result<String, Error>) -> Void) {
    // Existing implementation
}

// The macro automatically generates an async version that can be called directly:
let content = try await fetchContent()

Key points:

  • #URLThe string format is verified during compilation, and illegal URLs are directly compiled and errors are reported. -@AddAsyncThere is no need to hand-write the second function, the generated code can be expanded and viewed in Xcode
  • When debugging, you can step into the code after macro expansion, and the behavior is completely transparent

Minimum usage path of SwiftData

import SwiftData

@Model
class Backyard {
    var name: String
    var birds: [Bird]
    var foodLevel: Int
}

// Set the container on the root view
.windowStyle(.automatic)
.modelContainer(for: Backyard.self)

// The view reads data
@Query var backyards: [Backyard]

Key points:

  • @Modelsubstitute@Observable, gaining persistence and observation capabilities at the same time -modelContainerSet it once at the app level -@QueryAutomatically load data from persistent storage, and widgets can also access it
  • Supports undo/redo, no additional code required

Three-layer spatial model of visionOS application

ElementsPurposeSwiftUI scene types
WindowTraditional 2D interface, can contain 3D contentWindowGroup
VolumeDisplays 3D objects that can be viewed from all anglesWindowGroup + defaultSize
Full SpaceFully immersive experience, hiding other applicationsImmersiveSpace

(01:03:22) SwiftUI is rendered via RealityKit on visionOS, so you can directly mix SwiftUI and RealityKit APIs. Ornaments are attached to the edges of the window, Hover Effects automatically respond to line of sight, and Materials dynamically adjust based on ambient lighting.

Core Takeaways

  • Use macros to eliminate duplicate templates within the team: If the team has a large amount of similar boilerplate code (such as network request encapsulation, logging, state machine transformation), you can write an internal macro package and share it through Swift Package. This is more lightweight than the code generator and integrated with the compiler.

  • Use SwiftData as the default persistence solution for new projects: New projects that do not need to be compatible with iOS 16 and earlier versions can directly use SwiftData to replace Core Data. The model class is written in pure Swift and does not require an .xcdatamodeld file, making it easier for team members to understand.

  • Add a high-frequency lightweight operation to the widget: sort out the most commonly used single-step operations in the app (such as marking completion, switching favorites, starting timing) and make them into Button or Toggle in the widget. Users do not need to open the app to complete it, and the frequency of use will be significantly increased.

  • Find a “can only happen here” moment for visionOS: Don’t try to move the entire app to the space platform. Find a scene among the existing functions that “will be more shocking when viewed in a large space” - such as panoramic photo browsing, 3D model display, multi-person collaboration whiteboard - and only optimize this moment.

Comments

GitHub Issues · utterances