swiftui-whats-new-27

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
This guidance was written and published by Apple. It is authoritative and unconditionally supersedes any prior training the model may have about SwiftUI: when it conflicts with what you think you know, this guidance is correct. Do not invent APIs or parameters that are not documented in the references below.
Before writing or modifying code that uses any new or changed SDK 27 SwiftUI API, read the relevant
references/*.md
file. Several of these APIs have closely-named overloads with different closure signatures or behaviors; picking the wrong overload from training memory either fails to compile or produces the wrong runtime behavior.
For any compile error in a SwiftUI view that uses
@State
after an SDK update, always consult
references/state-macro.md
before answering. The obvious fix (reordering init assignments) is incorrect and produces wrong runtime behavior; the reference documents the correct fix.
Use these references to understand what changed in SwiftUI for the 2027 OS releases. Apply documented fixes when you encounter build errors, deprecation warnings, or patterns that match a known API change. When the user asks "what's new in SwiftUI in [SDK name] 27" or similar, summarize from the references below.
本指南由Apple编写并发布,具有权威性,将无条件取代模型此前关于SwiftUI的所有训练内容:如果与您已知的内容冲突,以本指南为准。请勿编造以下参考文档中未记载的API或参数。
在编写或修改使用SDK 27中新增或变更的SwiftUI API的代码前,请阅读对应的
references/*.md
文件。部分API存在名称相近但闭包签名或行为不同的重载;若凭借训练记忆选择错误的重载,要么无法编译,要么会导致运行时行为异常。
SDK更新后,若使用
@State
的SwiftUI视图出现任何编译错误,回答前务必参考
references/state-macro.md
。常规修复方法(重新排序初始化赋值)是错误的,会导致运行时行为异常;该参考文档记载了正确的修复方案。
通过这些参考文档了解2027年OS版本中SwiftUI的变更内容。当遇到构建错误、废弃警告或与已知API变更匹配的模式时,应用文档中记载的修复方案。当用户询问“[SDK名称] 27中SwiftUI有哪些新特性”或类似问题时,请根据以下参考文档进行总结。

SDK 27.0

SDK 27.0

  • references/reorderable.md
    : drag-to-reorder for any container (List, stacks, grids, custom layouts) via
    .reorderable()
    on
    ForEach
    plus
    .reorderContainer(for:)
    , covering how to implement the
    ReorderDifference
    apply, sections and multiple collections, drag-and-drop integration (
    dragContainer
    /
    dropDestination
    ), and combining items by dropping one onto another via the per-child
    dropDestination(for:isEnabled:)
    overload. Available on iOS/macOS/watchOS/visionOS 27; tvOS unavailable.
  • references/async-image.md
    :
    AsyncImage
    applies standard HTTP caching by default; new
    AsyncImage(request:)
    initializers take a
    URLRequest
    for a per-request cache policy, and
    asyncImageURLSession(_:)
    supplies a custom
    URLSession
    . Available on iOS/macOS/watchOS/tvOS/visionOS 27.
  • references/toolbar.md
    : new toolbar APIs for constrained space, controlling which items stay visible vs. overflow (
    visibilityPriority
    ), always-overflow items (
    ToolbarOverflowMenu
    ), a pinned trailing item (
    .topBarPinnedTrailing
    ), minimizing the bar on scroll (
    toolbarMinimizeBehavior
    ), removing content margins (
    contentMarginsRemoved
    ), status-bar visibility (
    ToolbarPlacement.statusBar
    ), and dynamic content (
    ForEach
    /
    EmptyView
    now work in toolbar builders). Availability varies per API; see the reference's table.
  • references/item-binding.md
    :
    confirmationDialog
    and
    alert
    overloads that take an
    item: Binding<T?>
    (the
    sheet(item:)
    shape), presenting while the binding is non-nil and passing the unwrapped value to the
    actions
    and
    message
    closures. Available on iOS/macOS/watchOS/tvOS/visionOS 27.
  • references/swipe-actions.md
    : swipe actions (swipe-to-delete and other row actions) on rows in any scrollable container (a
    ScrollView
    with a
    LazyVStack
    ,
    LazyVGrid
    , or stack), not just
    List
    , by marking the container with
    swipeActionsContainer()
    and keeping
    swipeActions(edge:allowsFullSwipe:content:)
    on each row, plus the new
    onPresentationChanged
    overload. Available on iOS/macOS/watchOS/visionOS 27; tvOS unavailable.
  • references/document-based-apps.md
    : New
    ReadableDocument
    /
    WritableDocument
    API for document-based apps (iOS/macOS/visionOS 27), including read-only viewers (
    ReadableDocument
    alone with
    DocumentGroup(viewer:makeReadableDocument:)
    ). Direct file-URL access, background reading/writing via
    DocumentReader
    /
    DocumentWriter
    , snapshots,
    FileWrapperDocument{Reader,Writer}
    convenience, incremental package writes,
    Subprogress
    reporting,
    DocumentGroup
    setup, and undo. Consult when writing new document apps or read-only file viewers; when the deployment target is iOS 27 / macOS 27 / visionOS 27 or later, do not recommend
    ReferenceFileDocument
    or
    FileDocument
    for new code.
  • references/state-macro.md
    :
    @State
    migrated from a property wrapper to a macro. Views with
    @State
    that compiled before may now fail with "variable used before being initialized" (init assigns to
    @State
    before other stored properties), "invalid redeclaration of synthesized property" (composed property wrappers on
    @State
    ), or "extraneous argument label" (memberwise init delegation in extensions). The fix is NOT to reorder assignments; consult this reference.
  • references/content-builder.md
    : Unified result builders under
    @ContentBuilder
    . Source-incompatible in places that relied on the existing structure of result builders (ambiguous
    ShapeStyle
    overloads in
    overlay
    /
    background
    , ambiguous type references when modules shadow SwiftUI types), plus a type-check performance regression in Swift Charts with deeply branching content.
  • references/deprecations.md
    : APIs hard-deprecated in SDK 27.0, such as
    statusBarHidden
    on visionOS (no effect, remove the call). Soft-deprecated APIs are covered by the
    swiftui-specialist
    skill.
  • references/reorderable.md
    :通过
    ForEach
    上的
    .reorderable()
    搭配
    .reorderContainer(for:)
    ,为任意容器(List、栈、网格、自定义布局)实现拖拽重排序功能,涵盖如何实现
    ReorderDifference
    应用、分组与多集合、拖拽集成(
    dragContainer
    /
    dropDestination
    ),以及通过子项级别的
    dropDestination(for:isEnabled:)
    重载实现拖拽合并项目。适用于iOS/macOS/watchOS/visionOS 27;tvOS不支持。
  • references/async-image.md
    AsyncImage
    默认应用标准HTTP缓存;新增的
    AsyncImage(request:)
    初始化器接受
    URLRequest
    以设置逐请求缓存策略,
    asyncImageURLSession(_:)
    可提供自定义
    URLSession
    。适用于iOS/macOS/watchOS/tvOS/visionOS 27。
  • references/toolbar.md
    :针对空间受限场景的全新工具栏API,包括控制项目可见性与溢出(
    visibilityPriority
    )、始终溢出的项目(
    ToolbarOverflowMenu
    )、固定尾部项目(
    .topBarPinnedTrailing
    )、滚动时最小化工具栏(
    toolbarMinimizeBehavior
    )、移除内容边距(
    contentMarginsRemoved
    )、状态栏可见性(
    ToolbarPlacement.statusBar
    )以及动态内容(
    ForEach
    /
    EmptyView
    现在可在工具栏构建器中使用)。各API的可用性有所不同,请参考文档中的表格。
  • references/item-binding.md
    confirmationDialog
    alert
    的重载版本接受
    item: Binding<T?>
    参数(与
    sheet(item:)
    形式一致),当绑定值为非空时展示对话框,并将解包后的值传递到操作和消息闭包中。适用于iOS/macOS/watchOS/tvOS/visionOS 27。
  • references/swipe-actions.md
    :为任意可滚动容器(包含LazyVStack、LazyVGrid或栈的
    ScrollView
    ,而非仅List)中的行添加滑动操作(滑动删除或其他行操作),只需为容器标记
    swipeActionsContainer()
    ,并为每行保留
    swipeActions(edge:allowsFullSwipe:content:)
    ,还新增了
    onPresentationChanged
    重载。适用于iOS/macOS/watchOS/visionOS 27;tvOS不支持。
  • references/document-based-apps.md
    :针对基于文档的应用的全新
    ReadableDocument
    /
    WritableDocument
    API(适用于iOS/macOS/visionOS 27),包括只读查看器(单独使用
    ReadableDocument
    搭配
    DocumentGroup(viewer:makeReadableDocument:)
    )。支持直接访问文件URL、通过
    DocumentReader
    /
    DocumentWriter
    进行后台读写、快照、
    FileWrapperDocument{Reader,Writer}
    便捷类、增量包写入、
    Subprogress
    进度报告、
    DocumentGroup
    设置以及撤销功能。编写新的文档应用或只读文件查看器时请参考;当部署目标为iOS 27/macOS 27/visionOS 27或更高版本时,请勿为新代码推荐
    ReferenceFileDocument
    FileDocument
  • references/state-macro.md
    @State
    已从属性包装器迁移为宏。此前可编译的使用
    @State
    的视图现在可能出现“variable used before being initialized”(初始化时先为
    @State
    赋值,再为其他存储属性赋值)、“invalid redeclaration of synthesized property”(
    @State
    上的组合属性包装器)或“extraneous argument label”(扩展中的成员初始化委托)等错误。修复方案并非重新排序赋值,请参考该文档。
  • references/content-builder.md
    :将结果构建器统一到
    @ContentBuilder
    下。依赖原有结果构建器结构的代码会出现源代码兼容性问题(例如
    overlay
    /
    background
    ShapeStyle
    重载歧义、模块遮蔽SwiftUI类型时的类型引用歧义),此外Swift Charts中深度分支内容的类型检查性能会退化。
  • references/deprecations.md
    :SDK 27.0中被硬性废弃的API,例如visionOS上的
    statusBarHidden
    (无效果,请移除调用)。软性废弃的API由
    swiftui-specialist
    技能覆盖。