New
139struct
AnyNavigationTransition
NewiOSmacOStvOSwatchOSpublic struct AnyNavigationTransition : NavigationTransition, ~Sendable
A type-erasing navigation transition that allows for providing any navigation transition value dynamically.
Use this navigation transition when you need to dynamically configure the transition of your content. For example, you could use this in a sheet(isPresented:onDismiss:content:) modifier to dynamically configure how the sheet transitions in and out.
This example shows a sheet that uses a different transition based on model state.
struct ContentView: View {
@State private var showSheet = false
@Environment(Model.self) var model
var body: some View {
VStack {
Button("Show Sheet") {
showSheet = true
}
.sheet(isPresented: $showSheet) {
let transition = model.useCrossDissolve
? AnyNavigationTransition(.crossFade)
: AnyNavigationTransition(.automatic)
Text("Sheet Content")
.presentationDetents([.medium])
.navigationTransition(transition)
}
}
}
}
Declaration
public struct AnyNavigationTransition : NavigationTransition, ~Sendable {
public init(_ transition: some NavigationTransition)
}
struct
CrossFadeNavigationTransition
NewiOStvOSwatchOSpublic struct CrossFadeNavigationTransition : NavigationTransition, Sendable
A navigation transition that cross-fades between the appearing view and the disappearing view.
Declaration
public struct CrossFadeNavigationTransition : NavigationTransition, Sendable {
}
struct
DefaultNewDocumentButtonLabel
NewiOSmacOSpublic struct DefaultNewDocumentButtonLabel : View
The default label used for a new document button.
You don't use this type directly. Instead, NewDocumentButton uses it automatically depending on how you create a button.
Declaration
@MainActor @preconcurrency public struct DefaultNewDocumentButtonLabel : View {
@MainActor @preconcurrency public init()
/// The content and behavior of the view.
///
/// When you implement a custom view, you must implement a computed
/// `body` property to provide the content for your view. Return a view
/// that's composed of built-in views that SwiftUI provides, plus other
/// composite views that you've already defined:
///
/// struct MyView: View {
/// var body: some View {
/// Text("Hello, World!")
/// }
/// }
///
/// For more information about composing views and a view hierarchy,
/// see <doc:Declaring-a-Custom-View>.
@MainActor @preconcurrency public var body: some View { get }
/// The type of view representing the body of this view.
///
/// When you create a custom view, Swift infers this type from your
/// implementation of the required ``View/body-swift.property`` property.
@available(macOS 27.0, iOS 27.0, *)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
public typealias Body = some View
}
struct
DocumentCreationContext
NewiOSmacOSpublic struct DocumentCreationContext
Provides context about how a document was created or opened.
Declaration
public struct DocumentCreationContext {
/// The source associated with the button that created this document.
///
/// On iOS, you can specify the source via ``NewDocumentButton`` in
/// ``DocumentGroupLaunchScene``. On macOS, this is always `nil`.
public var creationSource: DocumentCreationSource? { get }
}
extension
DocumentCreationContext
NewiOSmacOSextension DocumentCreationContext : CustomStringConvertible
Declaration
extension DocumentCreationContext : CustomStringConvertible {
/// A textual representation of this instance.
///
/// Calling this property directly is discouraged. Instead, convert an
/// instance of any type to a string by using the `String(describing:)`
/// initializer. This initializer works with any type, and uses the custom
/// `description` property for types that conform to
/// `CustomStringConvertible`:
///
/// struct Point: CustomStringConvertible {
/// let x: Int, y: Int
///
/// var description: String {
/// return "(\(x), \(y))"
/// }
/// }
///
/// let p = Point(x: 21, y: 30)
/// let s = String(describing: p)
/// print(s)
/// // Prints "(21, 30)"
///
/// The conversion of `p` to a string in the assignment to `s` uses the
/// `Point` type's `description` property.
public var description: String { get }
}
extension
DocumentCreationContext
NewiOSmacOSextension DocumentCreationContext : Hashable, Equatable
Declaration
extension DocumentCreationContext : Hashable, Equatable {
/// Returns a Boolean value indicating whether two values are equal.
///
/// Equality is the inverse of inequality. For any values `a` and `b`,
/// `a == b` implies that `a != b` is `false`.
///
/// - Parameters:
/// - lhs: A value to compare.
/// - rhs: Another value to compare.
public static func == (lhs: DocumentCreationContext, rhs: DocumentCreationContext) -> Bool
/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
/// Implement this method to conform to the `Hashable` protocol. The
/// components used for hashing must be the same as the components compared
/// in your type's `==` operator implementation. Call `hasher.combine(_:)`
/// with each of these components.
///
/// - Important: In your implementation of `hash(into:)`,
/// don't call `finalize()` on the `hasher` instance provided,
/// or replace it with a different instance.
/// Doing so may become a compile-time error in the future.
///
/// - Parameter hasher: The hasher to use when combining the components
/// of this instance.
public func hash(into hasher: inout Hasher)
/// The hash value.
///
/// Hash values are not guaranteed to be equal across different executions of
/// your program. Do not save hash values to use during a future execution.
///
/// - Important: `hashValue` is deprecated as a `Hashable` requirement. To
/// conform to `Hashable`, implement the `hash(into:)` requirement instead.
/// The compiler provides an implementation for `hashValue` for you.
public var hashValue: Int { get }
}
struct
DocumentCreationSource
NewiOSmacOSpublic struct DocumentCreationSource : Sendable, Hashable
Describes the source used to create a new document.
On iOS, you can declare custom creation sources and use them in NewDocumentButton.
extension DocumentCreationSource {
static let scanner: Self =
DocumentCreationSource(id: "document-from-scanner")
static let template: Self =
DocumentCreationSource(id: "document-from-template")
}
DocumentGroupLaunchScene("Documents") {
NewDocumentButton("Scan Document", source: .scanner)
NewDocumentButton("New from Template", source: .template)
}
When a document is created, you can retrieve its source from URLDocumentConfiguration or FileDocumentConfiguration:
DocumentGroup(newDocument: { MyDocument() }) { configuration in
if configuration.creationSource == .template {
TemplateSetupView()
}
}
Declaration
public struct DocumentCreationSource : Sendable, Hashable {
/// A string that uniquely identifies this creation source within your app.
public let id: String
/// Creates a document creation source with the given identifier.
///
/// Use different sources to distinguish between document creation flows
/// in your app.
///
/// extension DocumentCreationSource {
/// static let scanner: Self =
/// DocumentCreationSource(id: "document-from-scanner")
///
/// static let template: Self =
/// DocumentCreationSource(id: "document-from-template")
/// }
///
/// DocumentGroupLaunchScene("Documents") {
/// NewDocumentButton("Scan Document", source: .scanner)
/// NewDocumentButton("New from Template", source: .template)
/// }
///
/// When a document is created, you can retrieve its source from
/// ``URLDocumentConfiguration`` or ``FileDocumentConfiguration``.
///
/// - Parameter id: A string that uniquely identifies the creation flow
/// within your app.
@available(macOS, unavailable)
public init(id: String)
/// Returns a Boolean value indicating whether two values are equal.
///
/// Equality is the inverse of inequality. For any values `a` and `b`,
/// `a == b` implies that `a != b` is `false`.
///
/// - Parameters:
/// - lhs: A value to compare.
/// - rhs: Another value to compare.
public static func == (a: DocumentCreationSource, b: DocumentCreationSource) -> Bool
/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
/// Implement this method to conform to the `Hashable` protocol. The
/// components used for hashing must be the same as the components compared
/// in your type's `==` operator implementation. Call `hasher.combine(_:)`
/// with each of these components.
///
/// - Important: In your implementation of `hash(into:)`,
/// don't call `finalize()` on the `hasher` instance provided,
/// or replace it with a different instance.
/// Doing so may become a compile-time error in the future.
///
/// - Parameter hasher: The hasher to use when combining the components
/// of this instance.
public func hash(into hasher: inout Hasher)
/// The hash value.
///
/// Hash values are not guaranteed to be equal across different executions of
/// your program. Do not save hash values to use during a future execution.
///
/// - Important: `hashValue` is deprecated as a `Hashable` requirement. To
/// conform to `Hashable`, implement the `hash(into:)` requirement instead.
/// The compiler provides an implementation for `hashValue` for you.
public var hashValue: Int { get }
}
extension
DocumentGroup
NewiOSmacOSextension DocumentGroup where Document : Observable, Document : ReadableDocument, Document.Reader.Source == URL
Declaration
extension DocumentGroup where Document : Observable, Document : ReadableDocument, Document.Reader.Source == URL {
/// Creates a document group capable of opening and viewing read-only
/// documents.
///
/// - Parameters:
/// - viewer: The viewing UI for the provided document.
/// - makeDocument: A closure that creates the document
/// instance. Throw ``CancellationError`` to indicate that document
/// opening was cancelled.
nonisolated public init(@ContentBuilder viewer: @escaping (_ document: Document) -> Content, makeReadableDocument: @escaping (_ configuration: URLDocumentConfiguration, _ context: DocumentCreationContext) async throws -> Document)
}
extension
DocumentGroup
NewiOSmacOSextension DocumentGroup where Document : Observable, Document : ReadableDocument, Document : WritableDocument, Document.Reader.Source == URL, Document.Writer.Destination == URL
Declaration
extension DocumentGroup where Document : Observable, Document : ReadableDocument, Document : WritableDocument, Document.Reader.Source == URL, Document.Writer.Destination == URL {
/// Creates a document group capable of creating, viewing, and editing
/// documents.
///
/// - Parameters:
/// - allowCreating: Whether the document group supports creating
/// new documents in addition to opening and editing existing ones.
/// - editor: The editing UI for the provided document.
/// - makeDocument: A closure that creates the document instance.
/// Throw ``CancellationError`` to indicate that document creation
/// was cancelled.
nonisolated public init(allowCreating: Bool = true, @ContentBuilder editor: @escaping (_ document: Document) -> Content, makeDocument: @escaping (_ configuration: URLDocumentConfiguration, _ context: DocumentCreationContext) async throws -> Document)
}
struct
DocumentReadConfiguration
NewiOSmacOSpublic struct DocumentReadConfiguration
Provides the information required to read a document from disk.
Declaration
public struct DocumentReadConfiguration {
/// The format of the file to read.
public var contentType: UTType { get }
}
extension
DocumentReadConfiguration
NewiOSmacOSextension DocumentReadConfiguration : CustomStringConvertible
Declaration
extension DocumentReadConfiguration : CustomStringConvertible {
/// A textual representation of this instance.
///
/// Calling this property directly is discouraged. Instead, convert an
/// instance of any type to a string by using the `String(describing:)`
/// initializer. This initializer works with any type, and uses the custom
/// `description` property for types that conform to
/// `CustomStringConvertible`:
///
/// struct Point: CustomStringConvertible {
/// let x: Int, y: Int
///
/// var description: String {
/// return "(\(x), \(y))"
/// }
/// }
///
/// let p = Point(x: 21, y: 30)
/// let s = String(describing: p)
/// print(s)
/// // Prints "(21, 30)"
///
/// The conversion of `p` to a string in the assignment to `s` uses the
/// `Point` type's `description` property.
public var description: String { get }
}
extension
DocumentReadConfiguration
NewiOSmacOSextension DocumentReadConfiguration : Equatable
Declaration
extension DocumentReadConfiguration : Equatable {
/// Returns a Boolean value indicating whether two values are equal.
///
/// Equality is the inverse of inequality. For any values `a` and `b`,
/// `a == b` implies that `a != b` is `false`.
///
/// - Parameters:
/// - lhs: A value to compare.
/// - rhs: Another value to compare.
public static func == (a: DocumentReadConfiguration, b: DocumentReadConfiguration) -> Bool
}
extension
DocumentReadConfiguration
NewiOSmacOSextension DocumentReadConfiguration : Hashable
Declaration
extension DocumentReadConfiguration : Hashable {
/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
/// Implement this method to conform to the `Hashable` protocol. The
/// components used for hashing must be the same as the components compared
/// in your type's `==` operator implementation. Call `hasher.combine(_:)`
/// with each of these components.
///
/// - Important: In your implementation of `hash(into:)`,
/// don't call `finalize()` on the `hasher` instance provided,
/// or replace it with a different instance.
/// Doing so may become a compile-time error in the future.
///
/// - Parameter hasher: The hasher to use when combining the components
/// of this instance.
public func hash(into hasher: inout Hasher)
/// The hash value.
///
/// Hash values are not guaranteed to be equal across different executions of
/// your program. Do not save hash values to use during a future execution.
///
/// - Important: `hashValue` is deprecated as a `Hashable` requirement. To
/// conform to `Hashable`, implement the `hash(into:)` requirement instead.
/// The compiler provides an implementation for `hashValue` for you.
public var hashValue: Int { get }
}
protocol
DocumentReader
NewiOSmacOSpublic protocol DocumentReader<Snapshot>
Implements logic of reading documents from disk.
Declaration
public protocol DocumentReader<Snapshot> {
/// A type that represents the document's stored content.
associatedtype Snapshot
associatedtype Source
/// Reads the document from disk.
///
/// - Parameters:
/// - source: The source to read from.
/// - progress: The subprogress to report reading progress to
/// SwiftUI.
nonisolated func read(from source: sending Self.Source, progress: consuming Subprogress) async throws -> sending Self.Snapshot
}
struct
DocumentWriteConfiguration
NewiOSmacOSpublic struct DocumentWriteConfiguration
Provides the information required to write a document to disk.
Declaration
public struct DocumentWriteConfiguration {
/// The format of the file to write.
public var contentType: UTType { get }
}
extension
DocumentWriteConfiguration
NewiOSmacOSextension DocumentWriteConfiguration : CustomStringConvertible
Declaration
extension DocumentWriteConfiguration : CustomStringConvertible {
/// A textual representation of this instance.
///
/// Calling this property directly is discouraged. Instead, convert an
/// instance of any type to a string by using the `String(describing:)`
/// initializer. This initializer works with any type, and uses the custom
/// `description` property for types that conform to
/// `CustomStringConvertible`:
///
/// struct Point: CustomStringConvertible {
/// let x: Int, y: Int
///
/// var description: String {
/// return "(\(x), \(y))"
/// }
/// }
///
/// let p = Point(x: 21, y: 30)
/// let s = String(describing: p)
/// print(s)
/// // Prints "(21, 30)"
///
/// The conversion of `p` to a string in the assignment to `s` uses the
/// `Point` type's `description` property.
public var description: String { get }
}
protocol
DocumentWriter
NewiOSmacOSpublic protocol DocumentWriter<Snapshot>
Implements logic of writing documents to disk.
Declaration
public protocol DocumentWriter<Snapshot> {
/// A type that represents the document's stored content.
associatedtype Snapshot
associatedtype Destination
/// Writes the document content to disk.
///
/// - Parameters:
/// - content: The content to write to disk.
/// - destination: The destination to write to.
/// - previous: The previously written content. Use it to skip
/// writing unchanged data.
/// - progress: The subprogress to report writing progress to
/// SwiftUI.
nonisolated func write(content: sending Self.Snapshot, to destination: sending Self.Destination, previous: sending Self.Snapshot?, progress: consuming Subprogress) async throws
}
extension
DragGesture
NewiOSmacOSwatchOSextension DragGesture
Declaration
extension DragGesture {
/// Creates a dragging gesture with the minimum dragging distance before the
/// gesture succeeds, the coordinate space of the gesture's location, and
/// the input kinds the gesture recognizes.
///
/// - Parameters:
/// - minimumDistance: The minimum distance a person needs to drag
/// before the drag gesture begins.
/// - coordinateSpace: The coordinate space of the dragging gesture's
/// location.
/// - inputKinds: A set of input kinds that this gesture recognizes.
/// If not specified, the gesture will recognize all applicable input
/// kinds that a person can use to perform it.
@MainActor @preconcurrency public init(minimumDistance: CGFloat = 10, coordinateSpace: some CoordinateSpaceProtocol = .local, inputKinds: GestureInputKinds = .all)
}
extension
EmptyView
NewiOSmacOStvOSwatchOSextension EmptyView : ToolbarContent
Declaration
extension EmptyView : ToolbarContent {
}
extension
EmptyView
NewiOSmacOStvOSwatchOSextension EmptyView : CustomizableToolbarContent
Declaration
extension EmptyView : CustomizableToolbarContent {
}
extension
EmptyView
NewiOSmacOSextension EmptyView : Commands
Declaration
extension EmptyView : Commands {
}
extension
EmptyView
NewiOSextension EmptyView : SceneAccessoryContent
Declaration
extension EmptyView : SceneAccessoryContent {
}
struct
ExternalNonInteractiveAccessory
NewiOSnonisolated public struct ExternalNonInteractiveAccessory<Content> : SceneAccessoryContent where Content : View
A scene accessory that presents non-interactive content on an external display.
The scene accessory may be presented when an external display is connected to the device, or when the device is connected to an external display via AirPlay.
For example, you can define a scene accessory for previewing a non-interactive presentation, which may be presented when an external display is connected:
struct RootView: View {
var document: PresentationDocument
var body: some View {
PresentationDocumentView(document: document)
.sceneAccessory {
ExternalNonInteractiveAccessory {
PresentationPreview(document: document)
}
}
}
}
Declaration
nonisolated public struct ExternalNonInteractiveAccessory<Content> : SceneAccessoryContent where Content : View {
/// Creates a scene accessory that presents non-interactive content on an
/// external display.
///
/// - Parameters:
/// - content: The scene's content.
nonisolated public init(@ContentBuilder content: @escaping () -> Content)
/// Creates a scene accessory that presents non-interactive content on an
/// external display with a binding for programmatic enablement.
///
/// - Parameters:
/// - isEnabled: A binding for whether or not the accessory should present
/// if available.
/// - content: The scene's content.
nonisolated public init(isEnabled: Binding<Bool>, @ContentBuilder content: @escaping () -> Content)
/// The composition of content that comprise the accessory content.
nonisolated public var body: some SceneAccessoryContent { get }
/// The type of content representing the body of this scene accessory
/// content.
@available(iOS 27.0, *)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(macCatalyst, unavailable)
@available(visionOS, unavailable)
public typealias Body = some SceneAccessoryContent
}
extension
FileDocumentConfiguration
NewiOSextension FileDocumentConfiguration
Declaration
extension FileDocumentConfiguration {
/// The source associated with the button that created this document.
///
/// On iOS, you can specify the source via a ``NewDocumentButton`` in
/// ``DocumentGroupLaunchScene``:
///
/// extension DocumentCreationSource {
/// static let scanner: Self =
/// DocumentCreationSource(id: "document-from-scanner")
///
/// static let template: Self =
/// DocumentCreationSource(id: "document-from-template")
/// }
///
/// DocumentGroupLaunchScene("Documents") {
/// NewDocumentButton("Scan Document", source: .scanner)
/// NewDocumentButton("New from Template", source: .template)
/// }
///
/// Use this property to determine which ``NewDocumentButton`` triggered
/// the creation of the current document, allowing you to customize the UI
/// accordingly.
public var creationSource: DocumentCreationSource? { get }
}
struct
FileWrapperDocumentReader
NewiOSmacOSpublic struct FileWrapperDocumentReader<Snapshot> : DocumentReader
A document reader that uses FileWrapper for reading.
Use FileWrapperDocumentReader for simple cases where the application does not need custom reading logic. It is efficient for documents of small and medium size.
Note: For large files or packages, provide a custom DocumentReader that reads only what changed.
Declaration
public struct FileWrapperDocumentReader<Snapshot> : DocumentReader {
public typealias ReadConfiguration = DocumentReadConfiguration
public typealias Source = URL
/// Creates a reader that uses `FileWrapper` to read documents from disk.
///
/// - Parameters:
/// - configuration: Properties required to read a document from disk.
/// - makeSnapshot: Deserializes a `FileWrapper` into a `Snapshot`.
/// Throw an error if the data is malformed.
public init(_ configuration: sending FileWrapperDocumentReader<Snapshot>.ReadConfiguration, makeSnapshot: @escaping (FileWrapper) async throws -> sending Snapshot)
/// Reads the document from disk.
///
/// - Parameters:
/// - source: The source to read from.
/// - progress: The subprogress to report reading progress to
/// SwiftUI.
nonisolated public func read(from source: sending URL, progress: consuming Subprogress) async throws -> sending Snapshot
}
struct
FileWrapperDocumentWriter
NewiOSmacOSpublic struct FileWrapperDocumentWriter<Snapshot> : DocumentWriter
A document writer that uses FileWrapper for writing.
Use FileWrapperDocumentWriter for simple cases where the application does not need custom writing logic. It is efficient for documents of small and medium size.
Note: For large files or packages, provide a custom DocumentWriter that writes only what changed.
Declaration
public struct FileWrapperDocumentWriter<Snapshot> : DocumentWriter {
public typealias WriteConfiguration = DocumentWriteConfiguration
public typealias Destination = URL
/// Creates a writer that uses `FileWrapper` to write documents to disk.
///
/// - Parameters:
/// - configuration: Properties required to write a document to disk.
/// - makeFileWrapper: Serializes a `Snapshot` into a `FileWrapper`.
public init(_ configuration: sending FileWrapperDocumentWriter<Snapshot>.WriteConfiguration, makeFileWrapper: @escaping (Snapshot) async throws -> FileWrapper)
/// Writes the document content to disk.
///
/// - Parameters:
/// - content: The content to write to disk.
/// - destination: The destination to write to.
/// - previous: The previously written content. Use it to skip
/// writing unchanged data.
/// - progress: The subprogress to report writing progress to
/// SwiftUI.
nonisolated public func write(content: sending Snapshot, to destination: sending URL, previous: sending Snapshot?, progress: consuming Subprogress) async throws
}
extension
Group
NewiOSextension Group : SceneAccessoryContent where Content : SceneAccessoryContent
Declaration
extension Group : SceneAccessoryContent where Content : SceneAccessoryContent {
}
extension
LongPressGesture
NewiOSmacOSvisionOSwatchOSextension LongPressGesture
Declaration
extension LongPressGesture {
/// Creates a long-press gesture with a minimum duration, a maximum
/// distance, and the input kinds the gesture recognizes.
///
/// - Parameters:
/// - minimumDuration: The minimum duration of the long press that
/// must elapse before the gesture succeeds.
/// - maximumDistance: The maximum distance that the fingers or
/// cursor performing the long press can move before the gesture
/// fails.
/// - inputKinds: A set of input kinds that this gesture recognizes. If
/// not specified, the gesture will recognize all applicable input kinds
/// that a person can use to perform it.
nonisolated public init(minimumDuration: Double = 0.5, maximumDistance: CGFloat = 10, inputKinds: GestureInputKinds = .all)
}
extension
MagnifyGesture
NewiOSmacOSvisionOSextension MagnifyGesture
Declaration
extension MagnifyGesture {
/// Creates a magnify gesture with a given minimum delta for the gesture
/// to start, and the input kinds the gesture recognizes.
///
/// - Parameters:
/// - minimumScaleDelta: The minimum scale delta required before the
/// gesture starts.
/// - inputKinds: A set of input kinds that this gesture recognizes.
/// If not specified, the gesture will recognize all applicable input
/// kinds that a person can use to perform it.
nonisolated public init(minimumScaleDelta: CGFloat = 0.01, inputKinds: GestureInputKinds = .all)
}
extension
NavigationTransition
NewiOStvOSwatchOSextension NavigationTransition where Self == CrossFadeNavigationTransition
Declaration
extension NavigationTransition where Self == CrossFadeNavigationTransition {
/// A navigation transition that cross-fades between the appearing
/// view and the disappearing view.
///
/// Specify this transition in a sheet to have it appear by fading
/// in over the content, as opposed to moving upwards to cover
/// content.
///
/// This example shows a sheet that appears with a cross-fade.
///
/// struct ContentView: View {
/// @State private var showSheet = false
///
/// var body: some View {
/// VStack {
/// Button("Show Sheet") {
/// showSheet = true
/// }
/// .sheet(isPresented: $showSheet) {
/// Text("Sheet Content")
/// .presentationDetents([.medium])
/// .navigationTransition(.crossFade)
/// }
/// }
/// }
/// }
///
public static var crossFade: CrossFadeNavigationTransition { get }
}
extension
Never
NewiOSextension Never : SceneAccessoryContent
Declaration
extension Never : SceneAccessoryContent {
}
extension
NewDocumentButton
NewiOSextension NewDocumentButton where Label == Text
Declaration
extension NewDocumentButton where Label == Text {
/// Creates and opens new documents, tagging them with a creation source.
///
/// extension DocumentCreationSource {
/// static let brainstorming: Self =
/// DocumentCreationSource(id: "brainstorming")
/// }
///
/// DocumentGroupLaunchScene("Meeting Minutes") {
/// NewDocumentButton(Text("New meeting minutes…"))
/// NewDocumentButton(
/// Text("New brainstorming meeting…"),
/// source: .brainstorming
/// )
/// }
///
/// - Parameters:
/// - label: A label for the button.
/// - contentType: An optional content type of the document to create.
/// If not provided, the first content type of the first document type
/// listed in the app definition is used.
/// - source: A source for the document creation flow. When a document is
/// created, you can retrieve its source from ``FileDocumentConfiguration``
/// or ``URLDocumentConfiguration``.
nonisolated public init(_ label: Text? = nil, contentType: UTType? = nil, source: DocumentCreationSource)
/// Creates and opens new documents, tagging them with a creation source.
///
/// - Parameters:
/// - title: A title key to use as the button title.
/// - contentType: An optional content type of the document to create.
/// - source: A source for the document creation flow. When a document is
/// created, you can retrieve its source from ``FileDocumentConfiguration``
/// or ``URLDocumentConfiguration``.
nonisolated public init(_ title: LocalizedStringKey, contentType: UTType? = nil, source: DocumentCreationSource)
/// Creates and opens new documents, tagging them with a creation source.
///
/// - Parameters:
/// - title: A title string to use as the button title.
/// - contentType: An optional content type of the document to create.
/// - source: A source for the document creation flow. When a document is
/// created, you can retrieve its source from ``FileDocumentConfiguration``
/// or ``URLDocumentConfiguration``.
nonisolated public init(_ title: some StringProtocol, contentType: UTType? = nil, source: DocumentCreationSource)
/// Creates and opens new documents, tagging them with a creation source.
///
/// - Parameters:
/// - title: A localized string resource to use as the button title.
/// - contentType: An optional content type of the document to create.
/// - source: A source for the document creation flow. When a document is
/// created, you can retrieve its source from ``FileDocumentConfiguration``
/// or ``URLDocumentConfiguration``.
nonisolated public init(_ title: LocalizedStringResource, contentType: UTType? = nil, source: DocumentCreationSource)
/// Creates and opens new documents from a template picker.
///
/// NewDocumentButton(
/// Text("New from template"),
/// for: TextDocument.self,
/// source: .template
/// ) {
/// try await withCheckedThrowingContinuation { continuation in
/// documentCreationContinuation = continuation
/// showTemplatePicker = true
/// }
/// }
///
/// - Parameters:
/// - label: A label for the button.
/// - documentType: The type of document to create.
/// - contentType: An optional content type of the document to create.
/// - source: A source for the document creation flow. When a document is
/// created, you can retrieve its source from ``FileDocumentConfiguration``
/// or ``URLDocumentConfiguration``.
/// - prepareDocument: Called when the user taps the button. Present a
/// template picker or other UI, then return the prepared document,
/// `nil` to request an empty document, or throw on cancellation.
Truncated.
extension
NewDocumentButton
NewiOSmacOSextension NewDocumentButton where Label == DefaultNewDocumentButtonLabel
Declaration
extension NewDocumentButton where Label == DefaultNewDocumentButtonLabel {
/// Creates and opens new documents from a specified source.
///
/// The button creates new documents of the writable content types
/// of all the document types supported by `DocumentGroup`s in
/// the App definition. If a document type is not associated with
/// any `DocumentGroup`, the button won't create new documents
/// of that type.
///
/// The framework watches for the relevant content types on the
/// pasteboard. When there are no matching or conforming types,
/// the button is disabled.
///
/// - Parameter source: A source of data that fills the newly
/// created document.
nonisolated public init(source: NewDocumentButtonDataSource)
/// Creates a button that creates new documents using data from
/// pasteboard.
///
/// struct NewTextDocumentFromPasteboardButton: View {
/// var body: some View {
/// NewDocumentButton(
/// for: TextDocument.self, source: .pasteboard
/// )
/// }
/// }
///
/// struct TextDocument: FileDocument { ... }
///
/// - Parameters:
/// - type: Type of documents to create from pasteboard data.
/// - source: A source of data that fills the newly created
/// document.
nonisolated public init<D>(for type: D.Type, source: NewDocumentButtonDataSource) where D : FileDocument
/// Creates a button that creates new documents using data from
/// pasteboard.
///
/// struct NewTextDocumentFromPasteboardButton: View {
/// var body: some View {
/// NewDocumentButton(
/// for: TextDocument.self, source: .pasteboard
/// )
/// }
/// }
///
/// class TextDocument: ReferenceFileDocument { ... }
///
/// - Parameters:
/// - type: Type of documents to create from pasteboard data.
/// - source: A source of data that fills the newly created
/// document.
nonisolated public init<D>(for type: D.Type, source: NewDocumentButtonDataSource) where D : ReferenceFileDocument
}
struct
NewDocumentButtonDataSource
NewiOSmacOSpublic struct NewDocumentButtonDataSource : Sendable, Hashable
Describes the source of data used to create a new document.
Declaration
public struct NewDocumentButtonDataSource : Sendable, Hashable {
/// Returns a Boolean value indicating whether two values are equal.
///
/// Equality is the inverse of inequality. For any values `a` and `b`,
/// `a == b` implies that `a != b` is `false`.
///
/// - Parameters:
/// - lhs: A value to compare.
/// - rhs: Another value to compare.
public static func == (lhs: NewDocumentButtonDataSource, rhs: NewDocumentButtonDataSource) -> Bool
/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
/// Implement this method to conform to the `Hashable` protocol. The
/// components used for hashing must be the same as the components compared
/// in your type's `==` operator implementation. Call `hasher.combine(_:)`
/// with each of these components.
///
/// - Important: In your implementation of `hash(into:)`,
/// don't call `finalize()` on the `hasher` instance provided,
/// or replace it with a different instance.
/// Doing so may become a compile-time error in the future.
///
/// - Parameter hasher: The hasher to use when combining the components
/// of this instance.
public func hash(into hasher: inout Hasher)
/// The hash value.
///
/// Hash values are not guaranteed to be equal across different executions of
/// your program. Do not save hash values to use during a future execution.
///
/// - Important: `hashValue` is deprecated as a `Hashable` requirement. To
/// conform to `Hashable`, implement the `hash(into:)` requirement instead.
/// The compiler provides an implementation for `hashValue` for you.
public var hashValue: Int { get }
}
extension
Optional
NewiOSmacOStvOSwatchOSextension Optional : AccessibilityRotorContent where Wrapped : AccessibilityRotorContent
Declaration
extension Optional : AccessibilityRotorContent where Wrapped : AccessibilityRotorContent {
/// The type for the internal content of this `AccessibilityRotorContent`.
@available(macOS 27.0, iOS 27.0, tvOS 27.0, watchOS 27.0, *)
public typealias Body = Never
}
extension
Optional
NewiOSextension Optional : SceneAccessoryContent where Wrapped : SceneAccessoryContent
Declaration
extension Optional : SceneAccessoryContent where Wrapped : SceneAccessoryContent {
/// The type of content representing the body of this scene accessory
/// content.
@available(iOS 27.0, *)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(macCatalyst, unavailable)
@available(visionOS, unavailable)
public typealias Body = Never
}
extension
PickerStyle
NewiOSmacOStvOSextension PickerStyle where Self == TabsPickerStyle
Declaration
extension PickerStyle where Self == TabsPickerStyle {
/// A picker style that presents options as segmented tabs.
///
/// On macOS, this style produces a segmented picker with a visual treatment
/// that distinguishes tab navigation from value selection. On iOS, tvOS,
/// and visionOS, the visual appearance matches that of the standard
/// standard `.segmented` style. On all supported platforms, VoiceOver announces
/// options as tabs.
///
/// ```swift
/// Picker("View", selection: $view) {
/// Text("Events").tag(Views.events)
/// Text("Reminders").tag(Views.reminders)
/// }
/// .pickerStyle(.tabs)
/// ```
///
/// To apply this style to a picker, or to a view that contains pickers,
/// use the ``View/pickerStyle(_:)`` modifier.
public static var tabs: TabsPickerStyle { get }
}
protocol
ReadableDocument
NewiOSmacOSpublic protocol ReadableDocument : AnyObject
A type that you use to read documents from file.
To create a read-only document type, conform to ReadableDocument and implement the required methods and properties. For a read-write document, also conform to WritableDocument, or use the Document typealias.
Your implementation:
- Provides readable content types via
readableContentTypes. - Loads documents from file using a
DocumentReader returned
by reader(configuration:).
- Applies loaded content to your model via
apply(snapshot:previous:).
Declaration
public protocol ReadableDocument : AnyObject {
/// A type that implements reading from disk logic.
associatedtype Reader : DocumentReader
/// The configuration for reading document contents.
typealias ReadConfiguration = DocumentReadConfiguration
/// The file and data types that the document reads from.
static var readableContentTypes: [UTType] { get }
/// Creates a value that reads a document from disk.
///
/// - Parameters:
/// - configuration: Additional context for reading.
func reader(configuration: sending Self.ReadConfiguration) -> sending Self.Reader
/// Applies loaded content to the document model.
///
/// SwiftUI calls this method on the main actor after reading completes.
///
/// - Parameters:
/// - snapshot: The snapshot loaded from disk.
/// - previous: The previously loaded snapshot. Compare to `snapshot`
/// to update only what changed.
@MainActor func apply(snapshot: sending Self.Reader.Snapshot, previous: sending Self.Reader.Snapshot?) async throws
}
extension
ReadableDocument
NewiOSmacOSextension ReadableDocument where Self : WritableDocument
Declaration
extension ReadableDocument where Self : WritableDocument {
/// By default, a document that supports reading also supports writing
/// the same content types.
public static var writableContentTypes: [UTType] { get }
}
struct
ReorderableSingleCollectionIdentifier
NewiOSmacOStvOSvisionOSwatchOSpublic struct ReorderableSingleCollectionIdentifier : Hashable, Sendable
An opaque, empty type used to identify reorderable containers and modifiers expecting only a single collection.
Declaration
public struct ReorderableSingleCollectionIdentifier : Hashable, Sendable {
/// Returns a Boolean value indicating whether two values are equal.
///
/// Equality is the inverse of inequality. For any values `a` and `b`,
/// `a == b` implies that `a != b` is `false`.
///
/// - Parameters:
/// - lhs: A value to compare.
/// - rhs: Another value to compare.
public static func == (a: ReorderableSingleCollectionIdentifier, b: ReorderableSingleCollectionIdentifier) -> Bool
/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
/// Implement this method to conform to the `Hashable` protocol. The
/// components used for hashing must be the same as the components compared
/// in your type's `==` operator implementation. Call `hasher.combine(_:)`
/// with each of these components.
///
/// - Important: In your implementation of `hash(into:)`,
/// don't call `finalize()` on the `hasher` instance provided,
/// or replace it with a different instance.
/// Doing so may become a compile-time error in the future.
///
/// - Parameter hasher: The hasher to use when combining the components
/// of this instance.
public func hash(into hasher: inout Hasher)
/// The hash value.
///
/// Hash values are not guaranteed to be equal across different executions of
/// your program. Do not save hash values to use during a future execution.
///
/// - Important: `hashValue` is deprecated as a `Hashable` requirement. To
/// conform to `Hashable`, implement the `hash(into:)` requirement instead.
/// The compiler provides an implementation for `hashValue` for you.
public var hashValue: Int { get }
}
struct
ReorderDifference
NewiOSmacOStvOSvisionOSwatchOSpublic struct ReorderDifference<ItemID, CollectionID>
The difference produced by a reordering operation.
Declaration
public struct ReorderDifference<ItemID, CollectionID> {
/// The destination value of a reordering operation.
public struct Destination {
/// The position within the destination collection.
@frozen public enum Position {
/// The position of the item with the associated identifier in its
/// collection. Source items should be moved to the index of this
/// item.
case before(ItemID)
/// The end of the collection. Source items should be appended to
/// the end of the collection.
case end
}
/// The collection that contains the destination's position.
public var collectionID: CollectionID
/// The identifier position in the collection where the sources should
/// be moved to.
public var position: ReorderDifference<ItemID, CollectionID>.Destination.Position
/// Initializes the destination value with the provided position and
/// collectionID.
///
/// - Parameters:
/// - position: The position within the collection.
/// - destination: The identifier that represents this collection.
public init(position: ReorderDifference<ItemID, CollectionID>.Destination.Position, collectionID: CollectionID)
/// Initializes the destination value with the provided position and
/// an instance of `ReorderableSingleCollectionIdentifier`.
///
/// - Parameters:
/// - position: The position within the collection.
public init(position: ReorderDifference<ItemID, CollectionID>.Destination.Position) where CollectionID == ReorderableSingleCollectionIdentifier
}
/// The identifiers of items moved during a reordering operation.
public var sources: [ItemID]
/// The end position of items moved during a reordering operation.
public var destination: ReorderDifference<ItemID, CollectionID>.Destination
}
extension
ReorderDifference
NewiOSmacOStvOSvisionOSwatchOSextension ReorderDifference : Equatable where ItemID : Equatable, CollectionID : Equatable
Declaration
extension ReorderDifference : Equatable where ItemID : Equatable, CollectionID : Equatable {
/// Returns a Boolean value indicating whether two values are equal.
///
/// Equality is the inverse of inequality. For any values `a` and `b`,
/// `a == b` implies that `a != b` is `false`.
///
/// - Parameters:
/// - lhs: A value to compare.
/// - rhs: Another value to compare.
public static func == (a: ReorderDifference<ItemID, CollectionID>, b: ReorderDifference<ItemID, CollectionID>) -> Bool
}
extension
ReorderDifference
NewiOSmacOStvOSvisionOSwatchOSextension ReorderDifference : Hashable where ItemID : Hashable, CollectionID : Hashable
Declaration
extension ReorderDifference : Hashable where ItemID : Hashable, CollectionID : Hashable {
/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
/// Implement this method to conform to the `Hashable` protocol. The
/// components used for hashing must be the same as the components compared
/// in your type's `==` operator implementation. Call `hasher.combine(_:)`
/// with each of these components.
///
/// - Important: In your implementation of `hash(into:)`,
/// don't call `finalize()` on the `hasher` instance provided,
/// or replace it with a different instance.
/// Doing so may become a compile-time error in the future.
///
/// - Parameter hasher: The hasher to use when combining the components
/// of this instance.
public func hash(into hasher: inout Hasher)
/// The hash value.
///
/// Hash values are not guaranteed to be equal across different executions of
/// your program. Do not save hash values to use during a future execution.
///
/// - Important: `hashValue` is deprecated as a `Hashable` requirement. To
/// conform to `Hashable`, implement the `hash(into:)` requirement instead.
/// The compiler provides an implementation for `hashValue` for you.
public var hashValue: Int { get }
}
extension
ReorderDifference
NewiOSmacOStvOSvisionOSwatchOSextension ReorderDifference : Sendable where ItemID : Sendable, CollectionID : Sendable
Declaration
extension ReorderDifference : Sendable where ItemID : Sendable, CollectionID : Sendable {
}
extension
ReorderDifference.Destination
NewiOSmacOStvOSvisionOSwatchOSextension ReorderDifference.Destination : Equatable where ItemID : Equatable, CollectionID : Equatable
Declaration
extension ReorderDifference.Destination : Equatable where ItemID : Equatable, CollectionID : Equatable {
/// Returns a Boolean value indicating whether two values are equal.
///
/// Equality is the inverse of inequality. For any values `a` and `b`,
/// `a == b` implies that `a != b` is `false`.
///
/// - Parameters:
/// - lhs: A value to compare.
/// - rhs: Another value to compare.
public static func == (a: ReorderDifference<ItemID, CollectionID>.Destination, b: ReorderDifference<ItemID, CollectionID>.Destination) -> Bool
}
extension
ReorderDifference.Destination
NewiOSmacOStvOSvisionOSwatchOSextension ReorderDifference.Destination : Hashable where ItemID : Hashable, CollectionID : Hashable
Declaration
extension ReorderDifference.Destination : Hashable where ItemID : Hashable, CollectionID : Hashable {
/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
/// Implement this method to conform to the `Hashable` protocol. The
/// components used for hashing must be the same as the components compared
/// in your type's `==` operator implementation. Call `hasher.combine(_:)`
/// with each of these components.
///
/// - Important: In your implementation of `hash(into:)`,
/// don't call `finalize()` on the `hasher` instance provided,
/// or replace it with a different instance.
/// Doing so may become a compile-time error in the future.
///
/// - Parameter hasher: The hasher to use when combining the components
/// of this instance.
public func hash(into hasher: inout Hasher)
/// The hash value.
///
/// Hash values are not guaranteed to be equal across different executions of
/// your program. Do not save hash values to use during a future execution.
///
/// - Important: `hashValue` is deprecated as a `Hashable` requirement. To
/// conform to `Hashable`, implement the `hash(into:)` requirement instead.
/// The compiler provides an implementation for `hashValue` for you.
public var hashValue: Int { get }
}
extension
ReorderDifference.Destination
NewiOSmacOStvOSvisionOSwatchOSextension ReorderDifference.Destination : Sendable where ItemID : Sendable, CollectionID : Sendable
Declaration
extension ReorderDifference.Destination : Sendable where ItemID : Sendable, CollectionID : Sendable {
}
extension
ReorderDifference.Destination.Position
NewiOSmacOStvOSvisionOSwatchOSextension ReorderDifference.Destination.Position : Equatable where ItemID : Equatable
Declaration
extension ReorderDifference.Destination.Position : Equatable where ItemID : Equatable {
/// Returns a Boolean value indicating whether two values are equal.
///
/// Equality is the inverse of inequality. For any values `a` and `b`,
/// `a == b` implies that `a != b` is `false`.
///
/// - Parameters:
/// - lhs: A value to compare.
/// - rhs: Another value to compare.
public static func == (a: ReorderDifference<ItemID, CollectionID>.Destination.Position, b: ReorderDifference<ItemID, CollectionID>.Destination.Position) -> Bool
}
extension
ReorderDifference.Destination.Position
NewiOSmacOStvOSvisionOSwatchOSextension ReorderDifference.Destination.Position : Hashable where ItemID : Hashable
Declaration
extension ReorderDifference.Destination.Position : Hashable where ItemID : Hashable {
/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
/// Implement this method to conform to the `Hashable` protocol. The
/// components used for hashing must be the same as the components compared
/// in your type's `==` operator implementation. Call `hasher.combine(_:)`
/// with each of these components.
///
/// - Important: In your implementation of `hash(into:)`,
/// don't call `finalize()` on the `hasher` instance provided,
/// or replace it with a different instance.
/// Doing so may become a compile-time error in the future.
///
/// - Parameter hasher: The hasher to use when combining the components
/// of this instance.
public func hash(into hasher: inout Hasher)
/// The hash value.
///
/// Hash values are not guaranteed to be equal across different executions of
/// your program. Do not save hash values to use during a future execution.
///
/// - Important: `hashValue` is deprecated as a `Hashable` requirement. To
/// conform to `Hashable`, implement the `hash(into:)` requirement instead.
/// The compiler provides an implementation for `hashValue` for you.
public var hashValue: Int { get }
}
extension
ReorderDifference.Destination.Position
NewiOSmacOStvOSvisionOSwatchOSextension ReorderDifference.Destination.Position : Sendable where ItemID : Sendable
Declaration
extension ReorderDifference.Destination.Position : Sendable where ItemID : Sendable {
}
extension
RotateGesture
NewiOSmacOSvisionOSextension RotateGesture
Declaration
extension RotateGesture {
/// Creates a rotation gesture with a minimum delta for the gesture to
/// start, and the input kinds the gesture recognizes.
///
/// - Parameters:
/// - minimumAngleDelta: The minimum delta required before the gesture
/// starts. The default value is a one-degree angle.
/// - inputKinds: A set of input kinds that this gesture recognizes.
/// If not specified, the gesture will recognize all applicable input
/// kinds that a person can use to perform it.
nonisolated public init(minimumAngleDelta: Angle = .degrees(1), inputKinds: GestureInputKinds = .all)
}
extension
RotateGesture3D
NewvisionOSextension RotateGesture3D
Declaration
extension RotateGesture3D {
/// Creates a rotation gesture with a minimum delta for the gesture to
/// start, an axis to constrain measurement of rotation, and the input
/// kinds the gesture should recognize.
///
/// If the constrained axis is `nil`, the gesture measures unconstrained
/// 3D rotation.
///
/// - Parameters:
/// - constrainedToAxis: The 3D axis about which rotation is measured.
/// - minimumAngleDelta: The minimum delta required before the gesture
/// starts. The default value is a one-degree angle.
/// - inputKinds: A set of input kinds that this gesture recognizes.
/// If not specified, the gesture will recognize all applicable input
/// kinds that a person can use to perform it.
nonisolated public init(constrainedToAxis: RotationAxis3D? = nil, minimumAngleDelta: Angle = .degrees(1), inputKinds: GestureInputKinds = .all)
}
protocol
SceneAccessoryContent
NewiOSpublic protocol SceneAccessoryContent
Conforming types represent items which define content for scene accessories.
Declaration
@MainActor public protocol SceneAccessoryContent {
/// The type of content representing the body of this scene accessory
/// content.
associatedtype Body : SceneAccessoryContent
/// The composition of content that comprise the accessory content.
@ContentBuilder @MainActor var body: Self.Body { get }
}
extension
SceneAccessoryContent
NewiOSextension SceneAccessoryContent
Declaration
extension SceneAccessoryContent {
/// Defines a callback for observing the availability of `self`.
///
/// When the availability of a scene accessory changes,
/// the specified closure will be called.
///
/// For example, you can include additional controls based on
/// the availability:
///
/// struct RootView: View {
/// @State private var isEnabled = false
/// @State private var isAvailable = false
/// var document: PresentationDocument
///
/// var body: some View {
/// PresentationDocumentView(document: document)
/// .toolbar {
/// if isAvailable {
/// // Include a toolbar button to enable the
/// // scene accessory when a display is available.
/// SecondaryDisplayToggle(isEnabled: $isEnabled)
/// }
/// }
/// .sceneAccessory {
/// ExternalNonInteractiveAccessory(
/// isEnabled: $isEnabled
/// ) {
/// PresentationPreview(document: document)
/// }
/// .onAvailabilityChange { newValue in
/// isAvailable = newValue
/// }
/// }
/// }
/// }
nonisolated public func onAvailabilityChange(perform action: @escaping (_ isAvailable: Bool) -> Void) -> some SceneAccessoryContent
}
extension
SpatialTapGesture
NewiOSmacOSvisionOSwatchOSextension SpatialTapGesture
Declaration
extension SpatialTapGesture {
/// Creates a tap gesture with the number of required taps, the coordinate
/// space of the gesture's location, and the input kinds the gesture
/// recognizes.
///
/// - Parameters:
/// - count: The required number of taps to complete the tap gesture.
/// - coordinateSpace: The coordinate space of the tap gesture's
/// location.
/// - inputKinds: A set of input kinds that this gesture recognizes.
/// If not specified, the gesture will recognize all applicable input
/// kinds that a person can use to perform it.
nonisolated public init(count: Int = 1, coordinateSpace: some CoordinateSpaceProtocol = .local, inputKinds: GestureInputKinds = .all)
}
extension
TabContent
NewiOSmacOStvOSwatchOSextension TabContent
Declaration
extension TabContent {
/// Adds help text to a tab using a localized string that you provide.
///
/// Adding help to a tab configures the tab's accessibility hint and
/// its help tag (also called a _tooltip_) in macOS or visionOS.
/// For more information on using help tags, see
/// <doc://com.apple.documentation/design/human-interface-guidelines/offering-help>
/// in the Human Interface Guidelines.
///
/// TabView {
/// Tab("List", systemImage: "list.dash") {
/// ListView()
/// }
/// .help("Display symbols in list format")
/// }
///
/// - Parameter textKey: The key for the localized text to use as help.
nonisolated public func help(_ textKey: LocalizedStringKey) -> some TabContent<Self.TabValue>
/// Adds help text to a tab using a localized string resource that you
/// provide.
///
/// Adding help to a tab configures the tab's accessibility hint and
/// its help tag (also called a _tooltip_) in macOS or visionOS.
/// For more information on using help tags, see
/// <doc://com.apple.documentation/design/human-interface-guidelines/offering-help>
/// in the Human Interface Guidelines.
///
/// TabView {
/// Tab("List", systemImage: "list.dash") {
/// ListView()
/// }
/// .help("Display symbols in list format")
/// }
///
/// - Parameter textResource: Text resource for the localized text to use as help.
nonisolated public func help(_ textResource: LocalizedStringResource) -> some TabContent<Self.TabValue>
/// Adds help text to a tab using a string that you provide.
///
/// Adding help to a tab configures the tab's accessibility hint and
/// its help tag (also called a _tooltip_) in macOS or visionOS.
/// For more information on using help tags, see
/// <doc://com.apple.documentation/design/human-interface-guidelines/offering-help>
/// in the Human Interface Guidelines.
///
/// TabView {
/// Tab("List", systemImage: "list.dash") {
/// ListView()
/// }
/// .help("Display symbols in list format")
/// }
///
/// - Parameter text: The text to use as help.
nonisolated public func help<S>(_ text: S) -> some TabContent<Self.TabValue> where S : StringProtocol
/// Adds help text to a tab using a text view that you provide.
///
/// Adding help to a tab configures the tab's accessibility hint and
/// its help tag (also called a _tooltip_) in macOS or visionOS.
/// For more information on using help tags, see
/// <doc://com.apple.documentation/design/human-interface-guidelines/offering-help>
/// in the Human Interface Guidelines.
///
/// TabView {
/// Tab("List", systemImage: "list.dash") {
/// ListView()
/// }
/// .help(Text("Display symbols in list format"))
/// }
///
/// - Parameter text: The ``Text`` view to use as help.
nonisolated public func help(_ text: Text) -> some TabContent<Self.TabValue>
}
struct
TabSectionExpansion
NewiOSmacOStvOSvisionOSwatchOSpublic struct TabSectionExpansion : Sendable, Hashable
The default expansion state for a tab section in the sidebar.
Use this type in conjunction with the defaultSectionExpansion(_:) modifier.
Declaration
public struct TabSectionExpansion : Sendable, Hashable {
/// The system determines the default expansion state.
public static let automatic: TabSectionExpansion
/// The section is initially expanded in the sidebar.
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
public static let expanded: TabSectionExpansion
/// The section is initially collapsed in the sidebar.
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
public static let collapsed: TabSectionExpansion
/// Returns a Boolean value indicating whether two values are equal.
///
/// Equality is the inverse of inequality. For any values `a` and `b`,
/// `a == b` implies that `a != b` is `false`.
///
/// - Parameters:
/// - lhs: A value to compare.
/// - rhs: Another value to compare.
public static func == (a: TabSectionExpansion, b: TabSectionExpansion) -> Bool
/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
/// Implement this method to conform to the `Hashable` protocol. The
/// components used for hashing must be the same as the components compared
/// in your type's `==` operator implementation. Call `hasher.combine(_:)`
/// with each of these components.
///
/// - Important: In your implementation of `hash(into:)`,
/// don't call `finalize()` on the `hasher` instance provided,
/// or replace it with a different instance.
/// Doing so may become a compile-time error in the future.
///
/// - Parameter hasher: The hasher to use when combining the components
/// of this instance.
public func hash(into hasher: inout Hasher)
/// The hash value.
///
/// Hash values are not guaranteed to be equal across different executions of
/// your program. Do not save hash values to use during a future execution.
///
/// - Important: `hashValue` is deprecated as a `Hashable` requirement. To
/// conform to `Hashable`, implement the `hash(into:)` requirement instead.
/// The compiler provides an implementation for `hashValue` for you.
public var hashValue: Int { get }
}
struct
TabsPickerStyle
NewiOSmacOStvOSpublic struct TabsPickerStyle : PickerStyle
A picker style that presents options as segmented tabs.
On macOS, this style produces a segmented picker with a visual treatment that distinguishes tab navigation from value selection. On iOS, tvOS, and visionOS, the visual appearance matches that of the standard standard .segmented style. On all supported platforms, VoiceOver announces options as tabs.
Picker("View", selection: $view) {
Text("Events").tag(Views.events)
Text("Reminders").tag(Views.reminders)
}
.pickerStyle(.tabs)
To apply this style to a picker, or to a view that contains pickers, use the pickerStyle(_:) modifier.
You can also use tabs to construct this style.
Declaration
public struct TabsPickerStyle : PickerStyle {
/// Creates a tabs picker style.
public init()
}
extension
ToolbarContent
NewtvOSwatchOSextension ToolbarContent
Declaration
extension ToolbarContent {
/// Defines the visibility priority for a toolbar item.
///
/// When toolbar space is limited, items with a lower priority
/// move into the overflow menu before items with a higher priority.
/// The default is ``ToolbarItemVisibilityPriority/automatic``.
///
/// For example, an important control can appear at the trailing edge
/// of the toolbar, but still be shown as the window is made smaller:
///
/// struct RootView: View {
/// var body: some View {
/// ContentView()
/// .toolbar {
/// ToolbarItem {
/// SecondaryControl()
/// }
/// ToolbarItem {
/// PrimaryControl()
/// }
/// .visibilityPriority(.high)
/// }
/// }
/// }
///
/// - Parameter priority: The visibility priority for this toolbar
/// item.
@MainActor @preconcurrency public func visibilityPriority(_ priority: ToolbarItemVisibilityPriority) -> some ToolbarContent
}
struct
ToolbarItemVisibilityPriority
NewiOStvOSwatchOSpublic struct ToolbarItemVisibilityPriority : Hashable, Sendable
A value that defines the visibility priority of a toolbar item.
When a toolbar runs out of space, it moves items into an overflow menu. Visibility priority controls the order in which that happens: items with a lower priority move first, keeping higher-priority items visible longer as the window shrinks.
Use values of this type with the visibilityPriority(_:) modifier. For example, to keep a share button visible longer than an archive button:
struct RootView: View {
var body: some View {
ContentView()
.toolbar {
ToolbarItem {
SecondaryControl()
}
ToolbarItem {
PrimaryControl()
}
.visibilityPriority(.high)
}
}
}
Declaration
public struct ToolbarItemVisibilityPriority : Hashable, Sendable {
/// The default priority that lets the system determine the item's
/// visibility in the toolbar.
public static let automatic: ToolbarItemVisibilityPriority
/// A priority that moves the item to the overflow menu before
/// items with the default or high priority.
///
/// Use for secondary actions, such as archive or delete, that
/// don't need persistent visibility in the toolbar.
@available(iOS 27.0, macOS 26.1, *)
@available(watchOS, unavailable)
@available(tvOS, unavailable)
@available(visionOS, unavailable)
public static let low: ToolbarItemVisibilityPriority
/// A priority that keeps the item in the toolbar longer than
/// items with the default or low priority.
///
/// Use for frequently used actions that need to stay visible as
/// the toolbar shrinks.
@available(iOS 27.0, macOS 26.1, *)
@available(watchOS, unavailable)
@available(tvOS, unavailable)
@available(visionOS, unavailable)
public static let high: ToolbarItemVisibilityPriority
/// Creates a priority lower than the specified value.
///
/// The priority is lower than `other` but doesn't cross below
/// the next lower system priority. For example,
/// `ToolbarItemVisibilityPriority(lowerThan: .high)` returns a value
/// that is less than `.high` but greater than `.automatic`.
///
/// Priorities created with the same base value are equal:
///
/// let x = ToolbarItemVisibilityPriority(lowerThan: .high)
/// let y = ToolbarItemVisibilityPriority(lowerThan: .high)
/// x == y // true
///
@available(iOS 27.0, macOS 27.0, *)
@available(watchOS, unavailable)
@available(tvOS, unavailable)
@available(visionOS, unavailable)
public init(lowerThan other: ToolbarItemVisibilityPriority)
/// Creates a priority higher than the specified value.
///
/// The priority is higher than `other` but doesn't cross above
/// the next higher system priority. For example,
/// `ToolbarItemVisibilityPriority(higherThan: .high)` returns a
/// value that is greater than `.high`.
///
/// Priorities created with the same base value are equal:
///
/// let x = ToolbarItemVisibilityPriority(higherThan: .high)
/// let y = ToolbarItemVisibilityPriority(higherThan: .high)
/// x == y // true
///
@available(iOS 27.0, macOS 27.0, *)
@available(watchOS, unavailable)
@available(tvOS, unavailable)
@available(visionOS, unavailable)
public init(higherThan other: ToolbarItemVisibilityPriority)
/// Returns a Boolean value indicating whether two values are equal.
///
/// Equality is the inverse of inequality. For any values `a` and `b`,
/// `a == b` implies that `a != b` is `false`.
///
/// - Parameters:
/// - lhs: A value to compare.
/// - rhs: Another value to compare.
public static func == (a: ToolbarItemVisibilityPriority, b: ToolbarItemVisibilityPriority) -> Bool
/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
/// Implement this method to conform to the `Hashable` protocol. The
Truncated.
extension
ToolbarItemVisibilityPriority
NewiOSmacOStvOSvisionOSwatchOSextension ToolbarItemVisibilityPriority : Comparable
Declaration
extension ToolbarItemVisibilityPriority : Comparable {
/// Returns a Boolean value indicating whether the value of the first
/// argument is less than that of the second argument.
///
/// This function is the only requirement of the `Comparable` protocol. The
/// remainder of the relational operator functions are implemented by the
/// standard library for any type that conforms to `Comparable`.
///
/// - Parameters:
/// - lhs: A value to compare.
/// - rhs: Another value to compare.
public static func < (lhs: ToolbarItemVisibilityPriority, rhs: ToolbarItemVisibilityPriority) -> Bool
}
struct
ToolbarMinimizationSafeAreaAdjustment
NewiOSmacOStvOSvisionOSwatchOSpublic struct ToolbarMinimizationSafeAreaAdjustment : Hashable, Sendable
The safe area adjustment during toolbar minimization.
Use this type with the toolbarMinimizationSafeAreaAdjustment(_:for:) modifier to control whether the safe area updates as bars minimize. By default the safe area adjusts interactively, but you can disable this to keep content in place -- for example, when displaying full-bleed media beneath a minimizing bar.
.toolbarMinimizeBehavior(
.onScrollDown, for: .navigationBar)
.toolbarMinimizationSafeAreaAdjustment(
.disabled, for: .navigationBar)
Declaration
public struct ToolbarMinimizationSafeAreaAdjustment : Hashable, Sendable {
/// The system determines the safe area adjustment.
public static let automatic: ToolbarMinimizationSafeAreaAdjustment
/// The safe area adjusts interactively as bars minimize.
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
public static let enabled: ToolbarMinimizationSafeAreaAdjustment
/// The safe area remains unchanged as bars minimize.
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
public static let disabled: ToolbarMinimizationSafeAreaAdjustment
/// Returns a Boolean value indicating whether two values are equal.
///
/// Equality is the inverse of inequality. For any values `a` and `b`,
/// `a == b` implies that `a != b` is `false`.
///
/// - Parameters:
/// - lhs: A value to compare.
/// - rhs: Another value to compare.
public static func == (a: ToolbarMinimizationSafeAreaAdjustment, b: ToolbarMinimizationSafeAreaAdjustment) -> Bool
/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
/// Implement this method to conform to the `Hashable` protocol. The
/// components used for hashing must be the same as the components compared
/// in your type's `==` operator implementation. Call `hasher.combine(_:)`
/// with each of these components.
///
/// - Important: In your implementation of `hash(into:)`,
/// don't call `finalize()` on the `hasher` instance provided,
/// or replace it with a different instance.
/// Doing so may become a compile-time error in the future.
///
/// - Parameter hasher: The hasher to use when combining the components
/// of this instance.
public func hash(into hasher: inout Hasher)
/// The hash value.
///
/// Hash values are not guaranteed to be equal across different executions of
/// your program. Do not save hash values to use during a future execution.
///
/// - Important: `hashValue` is deprecated as a `Hashable` requirement. To
/// conform to `Hashable`, implement the `hash(into:)` requirement instead.
/// The compiler provides an implementation for `hashValue` for you.
public var hashValue: Int { get }
}
struct
ToolbarMinimizeBehavior
NewiOSmacOStvOSvisionOSwatchOSpublic struct ToolbarMinimizeBehavior : Hashable, Sendable
The minimize behavior of a toolbar.
Use this type with the toolbarMinimizeBehavior(_:for:) modifier to control how toolbars minimize in response to scrolling.
On iOS, you can minimize the navigation bar using onScrollDown or onScrollUp:
NavigationStack {
ScrollView {
// ...
}
.toolbarMinimizeBehavior(
.onScrollDown, for: .navigationBar)
}
Declaration
public struct ToolbarMinimizeBehavior : Hashable, Sendable {
/// The system determines the minimize behavior. By default,
/// navigation bars on iOS will minimize when the view has a
/// searchable using the ``SearchFieldPlacement/toolbarPrincipal``
/// placement.
public static var automatic: ToolbarMinimizeBehavior { get }
/// Minimize when scrolling down.
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
public static let onScrollDown: ToolbarMinimizeBehavior
/// Minimize when scrolling up.
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
public static let onScrollUp: ToolbarMinimizeBehavior
/// The toolbar cannot be minimized.
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
public static let never: ToolbarMinimizeBehavior
/// Returns a Boolean value indicating whether two values are equal.
///
/// Equality is the inverse of inequality. For any values `a` and `b`,
/// `a == b` implies that `a != b` is `false`.
///
/// - Parameters:
/// - lhs: A value to compare.
/// - rhs: Another value to compare.
public static func == (a: ToolbarMinimizeBehavior, b: ToolbarMinimizeBehavior) -> Bool
/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
/// Implement this method to conform to the `Hashable` protocol. The
/// components used for hashing must be the same as the components compared
/// in your type's `==` operator implementation. Call `hasher.combine(_:)`
/// with each of these components.
///
/// - Important: In your implementation of `hash(into:)`,
/// don't call `finalize()` on the `hasher` instance provided,
/// or replace it with a different instance.
/// Doing so may become a compile-time error in the future.
///
/// - Parameter hasher: The hasher to use when combining the components
/// of this instance.
public func hash(into hasher: inout Hasher)
/// The hash value.
///
/// Hash values are not guaranteed to be equal across different executions of
/// your program. Do not save hash values to use during a future execution.
///
/// - Important: `hashValue` is deprecated as a `Hashable` requirement. To
/// conform to `Hashable`, implement the `hash(into:)` requirement instead.
/// The compiler provides an implementation for `hashValue` for you.
public var hashValue: Int { get }
}
extension
TupleContent
NewiOSmacOStvOSwatchOSextension TupleContent : ToolbarContent where repeat each Content : ToolbarContent
Declaration
extension TupleContent : ToolbarContent where repeat each Content : ToolbarContent {
/// The type of content representing the body of this toolbar content.
@available(macOS 27.0, iOS 27.0, tvOS 27.0, watchOS 27.0, *)
public typealias Body = Never
}
extension
TupleContent
NewiOSmacOStvOSwatchOSextension TupleContent : CustomizableToolbarContent where repeat each Content : CustomizableToolbarContent
Declaration
extension TupleContent : CustomizableToolbarContent where repeat each Content : CustomizableToolbarContent {
}
extension
TupleContent
NewiOSmacOStvOSwatchOSextension TupleContent : AccessibilityRotorContent where repeat each Content : AccessibilityRotorContent
Declaration
extension TupleContent : AccessibilityRotorContent where repeat each Content : AccessibilityRotorContent {
/// The type for the internal content of this `AccessibilityRotorContent`.
@available(macOS 27.0, iOS 27.0, tvOS 27.0, watchOS 27.0, *)
public typealias Body = Never
}
extension
TupleContent
NewiOSmacOSextension TupleContent : Commands where repeat each Content : Commands
Declaration
extension TupleContent : Commands where repeat each Content : Commands {
/// The type of commands that represents the body of this command hierarchy.
///
/// When you create custom commands, Swift infers this type from your
/// implementation of the required ``SwiftUI/Commands/body-swift.property``
/// property.
@available(macOS 27.0, iOS 27.0, *)
@available(tvOS, unavailable, introduced: 26.0)
@available(watchOS, unavailable, introduced: 26.0)
public typealias Body = Never
}
extension
TupleContent
NewiOSextension TupleContent : SceneAccessoryContent where repeat each Content : SceneAccessoryContent
Declaration
extension TupleContent : SceneAccessoryContent where repeat each Content : SceneAccessoryContent {
/// The type of content representing the body of this scene accessory
/// content.
@available(iOS 27.0, *)
@available(macOS, unavailable, introduced: 26.0)
@available(tvOS, unavailable, introduced: 26.0)
@available(watchOS, unavailable, introduced: 26.0)
@available(macCatalyst, unavailable)
@available(visionOS, unavailable)
public typealias Body = Never
}
protocol
UIHostingSceneDelegate
NewtvOSpublic protocol UIHostingSceneDelegate : UISceneDelegate
Extends UISceneDelegate to bridge SwiftUI scenes.
Declare any SwiftUI scenes you wish to activate from UIKit in the static rootScene property of your conforming class:
class HostingSceneDelegate: UIHostingSceneDelegate {
static var rootScene: some Scene {
WindowGroup(id: "swiftui-window") {
ContentView()
}
}
// Add UISceneDelegate lifecycle callbacks here
}
Use a class conforming to UIHostingSceneDelegate to activate a scene by its ID or presented value with UISceneSessionActivationRequest:
if let requestWithID = UISceneSessionActivationRequest(
hostingDelegateClass: HostingSceneDelegate.self,
id: "swiftui-window"
) {
UIApplication.shared.activateSceneSession(for: requestWithID)
}
if let requestWithData = UISceneSessionActivationRequest(
hostingDelegateClass: HostingSceneDelegate.self,
value: FavoriteNumber(13)
) {
UIApplication.shared.activateSceneSession(for: requestWithData)
}
When a SwiftUI scene declared in your rootScene property is activated, an instance of your conforming class will be created by SwiftUI and receive window scene lifecycle callbacks.
Your UIHostingSceneDelegate class can be used with a UISceneConfiguration in your app delegate's application(_:configurationForConnecting:options:)method to activate a SwiftUI scene in response to an external event:
class AppDelegate: UIApplicationDelegate {
func application(
_ app: UIApplication,
configurationForConnecting sceneSession: UISceneSession,
options: UIScene.ConnectionOptions
) -> UISceneConfiguration {
let config = UISceneConfiguration(
name: nil, sessionRole: sceneSession.role)
config.delegateClass = HostingSceneDelegate.self
return config
}
}
Declaration
public protocol UIHostingSceneDelegate : UISceneDelegate {
associatedtype RootScene : Scene
@SceneBuilder static var rootScene: Self.RootScene { get }
}
extension
URLDocumentConfiguration
NewiOSmacOSextension URLDocumentConfiguration : Sendable
Declaration
extension URLDocumentConfiguration : Sendable {
}
extension
URLDocumentConfiguration
NewiOSmacOSextension URLDocumentConfiguration : CustomStringConvertible
Declaration
extension URLDocumentConfiguration : CustomStringConvertible {
/// A textual representation of this instance.
///
/// Calling this property directly is discouraged. Instead, convert an
/// instance of any type to a string by using the `String(describing:)`
/// initializer. This initializer works with any type, and uses the custom
/// `description` property for types that conform to
/// `CustomStringConvertible`:
///
/// struct Point: CustomStringConvertible {
/// let x: Int, y: Int
///
/// var description: String {
/// return "(\(x), \(y))"
/// }
/// }
///
/// let p = Point(x: 21, y: 30)
/// let s = String(describing: p)
/// print(s)
/// // Prints "(21, 30)"
///
/// The conversion of `p` to a string in the assignment to `s` uses the
/// `Point` type's `description` property.
@MainActor final public var description: String { get }
}
extension
URLDocumentConfiguration
NewiOSmacOSextension URLDocumentConfiguration : Equatable, Hashable
Declaration
extension URLDocumentConfiguration : Equatable, Hashable {
/// Returns a Boolean value indicating whether two values are equal.
///
/// Equality is the inverse of inequality. For any values `a` and `b`,
/// `a == b` implies that `a != b` is `false`.
///
/// - Parameters:
/// - lhs: A value to compare.
/// - rhs: Another value to compare.
@MainActor public static func == (lhs: URLDocumentConfiguration, rhs: URLDocumentConfiguration) -> Bool
/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
/// Implement this method to conform to the `Hashable` protocol. The
/// components used for hashing must be the same as the components compared
/// in your type's `==` operator implementation. Call `hasher.combine(_:)`
/// with each of these components.
///
/// - Important: In your implementation of `hash(into:)`,
/// don't call `finalize()` on the `hasher` instance provided,
/// or replace it with a different instance.
/// Doing so may become a compile-time error in the future.
///
/// - Parameter hasher: The hasher to use when combining the components
/// of this instance.
@MainActor final public func hash(into hasher: inout Hasher)
/// The hash value.
///
/// Hash values are not guaranteed to be equal across different executions of
/// your program. Do not save hash values to use during a future execution.
///
/// - Important: `hashValue` is deprecated as a `Hashable` requirement. To
/// conform to `Hashable`, implement the `hash(into:)` requirement instead.
/// The compiler provides an implementation for `hashValue` for you.
nonisolated final public var hashValue: Int { get }
}
extension
URLDocumentConfiguration
NewiOSextension URLDocumentConfiguration
Declaration
extension URLDocumentConfiguration {
/// The source associated with the button that created this document.
///
/// On iOS, you can specify the source via a ``NewDocumentButton`` in
/// ``DocumentGroupLaunchScene``:
///
/// extension DocumentCreationSource {
/// static let scanner: Self =
/// DocumentCreationSource(id: "document-from-scanner")
///
/// static let template: Self =
/// DocumentCreationSource(id: "document-from-template")
/// }
///
/// DocumentGroupLaunchScene("Documents") {
/// NewDocumentButton("Scan Document", source: .scanner)
/// NewDocumentButton("New from Template", source: .template)
/// }
///
/// Use this property to determine which ``NewDocumentButton`` triggered
/// the creation of the current document, allowing you to customize the UI
/// accordingly.
@MainActor final public var creationSource: DocumentCreationSource? { get }
}
extension
URLDocumentConfiguration
NewiOSmacOSextension URLDocumentConfiguration : nonisolated Observable
Declaration
extension URLDocumentConfiguration : nonisolated Observable {
}
extension
ViewBuilder
NewiOSextension ViewBuilder
/ TODO: Do I need anything here?
Declaration
extension ViewBuilder {
public static func buildLimitedAvailability(_ content: any SceneAccessoryContent) -> some SceneAccessoryContent
}
protocol
WritableDocument
NewiOSmacOSpublic protocol WritableDocument : AnyObject
A type that you use to write documents to file.
Conform to WritableDocument in addition to ReadableDocument to support saving. You can also conform your type to Document protocol which conforms both to WritableDocument and ReadableDocument.
Your implementation:
- Provides writable content types via
writableContentTypes. - Provides a snapshot of the current document state via
snapshot(contentType:).
- Writes the snapshot to disk using a
DocumentWriter returned
by writer(configuration:).
Declaration
public protocol WritableDocument : AnyObject {
/// A type that implements writing to disk logic.
associatedtype Writer : DocumentWriter
/// The configuration for writing document contents.
typealias WriteConfiguration = DocumentWriteConfiguration
/// The file types that the document supports saving or exporting to.
static var writableContentTypes: [UTType] { get }
/// Creates a value that writes a document to disk.
///
/// - Parameters:
/// - configuration: Additional context for writing.
func writer(configuration: sending Self.WriteConfiguration) -> sending Self.Writer
/// Creates a snapshot of the document's current state to be saved.
///
/// SwiftUI calls this on the main actor when saving. Perform expensive
/// serialization inside
/// ``DocumentWriter.write(content:to:previous:progress:)``
/// rather than here.
///
/// - Parameters:
/// - contentType: The format of the data requested.
@MainActor func snapshot(contentType: UTType) async throws -> sending Self.Writer.Snapshot
}
init
AlertScene.init
NewmacOSnonisolated public init<T>(_ titleKey: LocalizedStringKey, item data: Binding<T?>, @ContentBuilder actions: (T) -> Actions) where Message == EmptyView
Creates an alert scene, using the given data to produce the alert's content with a title, and a set of actions. Note that this creates a text view on your behalf.
Parameters
titleKey- The title of the alert.
data- A binding to optional source of truth for the alert. The system presents the alert when the binding's value is non-nil. When someone presses or taps one of the alert's actions, the system sets this value to
nil and dismisses. The system passes the contents to the alert to populate the message and actions. actions- A
ContentBuilder returning the actions for the dialog.
init
AlertScene.init
NewmacOSnonisolated public init<T>(_ titleResource: LocalizedStringResource, item data: Binding<T?>, @ContentBuilder actions: (T) -> Actions) where Message == EmptyView
Creates an alert scene, using the given data to produce the alert's content with a title, and a set of actions. Note that this creates a text view on your behalf.
Parameters
titleResource- The title of the alert.
data- A binding to optional source of truth for the alert. The system presents the alert when the binding's value is non-nil. When someone presses or taps one of the alert's actions, the system sets this value to
nil and dismisses. The system passes the contents to the alert to populate the message and actions. actions- A
ContentBuilder returning the actions for the dialog.
init
AlertScene.init
NewmacOSnonisolated public init<S, T>(_ title: S, item data: Binding<T?>, @ContentBuilder actions: (T) -> Actions) where Message == EmptyView, S : StringProtocol
Creates an alert scene, using the given data to produce the alert's content with a title, and a set of actions. Note that this creates a text view on your behalf.
Parameters
title- The title of the alert.
data- A binding to optional source of truth for the alert. The system presents the alert when the binding's value is non-nil. When someone presses or taps one of the alert's actions, the system sets this value to
nil and dismisses. The system passes the contents to the alert to populate the message and actions. actions- A
ContentBuilder returning the actions for the dialog.
init
AlertScene.init
NewmacOSnonisolated public init<T>(_ title: Text, item data: Binding<T?>, @ContentBuilder actions: (T) -> Actions) where Message == EmptyView
Creates an alert scene, using the given data to produce the alert's content with a title, and a set of actions.
Parameters
title- The title of the alert.
data- A binding to optional source of truth for the alert. The system presents the alert when the binding's value is non-nil. When someone presses or taps one of the alert's actions, the system sets this value to
nil and dismisses. The system passes the contents to the alert to populate the message and actions. actions- A
ContentBuilder returning the actions for the dialog.
init
AlertScene.init
NewmacOSnonisolated public init<T>(_ titleKey: LocalizedStringKey, item data: Binding<T?>, @ContentBuilder actions: (T) -> Actions, @ContentBuilder message: (T) -> Message)
Creates an alert scene, using the given data to produce the alert's content with a title, a set of actions, and a message. Note that this creates a text view on your behalf.
Parameters
titleKey- The key for the localized string that is the title of the alert.
data- A binding to optional source of truth for the alert. The system presents the alert when the binding's value is non-nil. When someone presses or taps one of the alert's actions, the system sets this value to
nil and dismisses. The system passes the contents to the alert to populate the message and actions. actions- A
ContentBuilder returning the actions for the dialog. message- A
ContentBuilder returning the message for the dialog.
init
AlertScene.init
NewmacOSnonisolated public init<T>(_ titleResource: LocalizedStringResource, item data: Binding<T?>, @ContentBuilder actions: (T) -> Actions, @ContentBuilder message: (T) -> Message)
Creates an alert scene, using the given data to produce the alert's content with a title, a set of actions, and a message. Note that this creates a text view on your behalf.
Parameters
titleResource- Text resource for the localized string that is the title of the alert.
data- A binding to optional source of truth for the alert. The system presents the alert when the binding's value is non-nil. When someone presses or taps one of the alert's actions, the system sets this value to
nil and dismisses. The system passes the contents to the alert to populate the message and actions. actions- A
ContentBuilder returning the actions for the dialog. message- A
ContentBuilder returning the message for the dialog.
init
AlertScene.init
NewmacOSnonisolated public init<S, T>(_ title: S, item data: Binding<T?>, @ContentBuilder actions: (T) -> Actions, @ContentBuilder message: (T) -> Message) where S : StringProtocol
Creates an alert scene, using the given data to produce the alert's content with a title, a set of actions, and a message. Note that this creates a text view on your behalf.
Parameters
title- A text string used as the title of the alert.
data- A binding to optional source of truth for the alert. The system presents the alert when the binding's value is non-nil. When someone presses or taps one of the alert's actions, the system sets this value to
nil and dismisses. The system passes the contents to the alert to populate the message and actions. actions- A
ContentBuilder returning the actions for the dialog. message- A
ContentBuilder returning the message for the dialog.
init
AlertScene.init
NewmacOSnonisolated public init<T>(_ title: Text, item data: Binding<T?>, @ContentBuilder actions: (T) -> Actions, @ContentBuilder message: (T) -> Message)
Creates an alert scene, using the given data to produce the alert's content with a title, a set of actions, and a message.
Parameters
title- The title of the alert.
data- A binding to optional source of truth for the alert. The system presents the alert when the binding's value is non-nil. When someone presses or taps one of the alert's actions, the system sets this value to
nil and dismisses. The system passes the contents to the alert to populate the message and actions. actions- A
ContentBuilder returning the actions for the dialog. message- A
ContentBuilder returning the message for the dialog.
init
AsyncImage.init
NewiOSmacOStvOSvisionOSwatchOSnonisolated public init(request: URLRequest, scale: CGFloat = 1) where Content == Image
Loads and displays an image from the specified URLRequest.
Until the image loads, SwiftUI displays a default placeholder. When the load operation completes successfully, SwiftUI updates the view to show the loaded image. If the operation fails, SwiftUI continues to display the placeholder. The following example loads and displays an icon from an example server:
AsyncImage(request: URLRequest(url: imageURL))
If you want to customize the placeholder or apply image-specific modifiers --- like resizable(capInsets:resizingMode:) --- to the loaded image, use the init(request:scale:content:placeholder:) initializer instead.
Parameters
request- The URLRequest of the image to display.
scale- The scale to use for the image. The default is
1. Set a different value when loading images designed for higher resolution displays. For example, set a value of 2 for an image that you would name with the @2x suffix if stored in a file on disk.
init
AsyncImage.init
NewiOSmacOStvOSvisionOSwatchOSnonisolated public init<I, P>(request: URLRequest?, scale: CGFloat = 1, @ContentBuilder content: @escaping (Image) -> I, @ContentBuilder placeholder: @escaping () -> P) where Content == _AsyncImageConditionalContent<I, P>, I : View, P : View
Loads and displays a modifiable image from the specified URLRequest using a custom placeholder until the image loads.
Until the image loads, SwiftUI displays the placeholder view that you specify. When the load operation completes successfully, SwiftUI updates the view to show content that you specify, which you create using the loaded image. For example, you can show a green placeholder, followed by a tiled version of the loaded image:
AsyncImage(request: URLRequest(url: imageURL)) { image in
image.resizable(resizingMode: .tile)
} placeholder: {
Color.green
}
If the load operation fails, SwiftUI continues to display the placeholder. To be able to display a different view on a load error, use the init(url:scale:transaction:content:) initializer instead.
Parameters
request- The URLRequest of the image to display.
scale- The scale to use for the image. The default is
1. Set a different value when loading images designed for higher resolution displays. For example, set a value of 2 for an image that you would name with the @2x suffix if stored in a file on disk. content- A closure that takes the loaded image as an input, and returns the view to show. You can return the image directly, or modify it as needed before returning it.
placeholder- A closure that returns the view to show until the load operation completes successfully.
init
AsyncImage.init
NewiOSmacOStvOSvisionOSwatchOSnonisolated public init(request: URLRequest?, scale: CGFloat = 1, transaction: Transaction = Transaction(), @ContentBuilder content: @escaping (AsyncImagePhase) -> Content)
Loads and displays a modifiable image from the specified URLRequest in phases.
If you set the asynchronous image's URLRequest to nil, or after you set the request to a value but before the load operation completes, the phase is empty. After the operation completes, the phase becomes either failure(_:) or success(_:). In the first case, the phase's error value indicates the reason for failure. In the second case, the phase's image property contains the loaded image. Use the phase to drive the output of the content closure, which defines the view's appearance:
AsyncImage(url: URLRequest(url: imageURL)) { phase in
if let image = phase.image {
image // Displays the loaded image.
} else if phase.error != nil {
Color.red // Indicates an error.
} else {
Color.blue // Acts as a placeholder.
}
}
To add transitions when you change the URLRequest, apply an identifier to the AsyncImage.
You can specify the cache policy and timeout interval via request.
Parameters
request- The URLRequest of the image to display.
scale- The scale to use for the image. The default is
1. Set a different value when loading images designed for higher resolution displays. For example, set a value of 2 for an image that you would name with the @2x suffix if stored in a file on disk. transaction- The transaction to use when the phase changes.
content- A closure that takes the load phase as an input, and returns the view to display for the specified phase.
func
BackgroundTask.processingTask
NewiOStvOSwatchOSpublic static func processingTask(_ identifier: String) -> BackgroundTask<Void, Void>
A task that processes tasks in the background.
typealias
DefaultNewDocumentButtonLabel.Body
NewiOSmacOSpublic typealias Body = some View
The type of view representing the body of this view.
When you create a custom view, Swift infers this type from your implementation of the required body-swift.property property.
init
DropConfiguration.init
NewmacOSpublic init<ItemID, CollectionID>(operation: DropOperation, destination: ReorderDifference<ItemID, CollectionID>.Destination) where ItemID : Hashable, ItemID : Sendable, CollectionID : Hashable, CollectionID : Sendable
Creates a drop configuration with the provided operation and reorder destination.
Use this initializer when you want to decide where the destination value of the current reordering session should be. The value that you pass to this initializer will be the value used for this update.
If you don't want to update the destination value, or your dropDestination(for:isEnabled:action:) is not configured with a reorderContainer(for:in:move:), use the initializer variant that takes only a DropOperation.
Parameters
operation- The drop operation that the drop destination chooses to perform on the drop.
destination- The destination value for the reordering operation.
func
DropSession.reorderDestination
NewiOSmacOSnonisolated public func reorderDestination<Item, CollectionID>(for item: Item.Type, in collectionID: CollectionID.Type = ReorderableSingleCollectionIdentifier.self) -> ReorderDifference<Item.ID, CollectionID>.Destination? where Item : Identifiable
Provides the destination value of a reordering operation that occurred in the container associated with this drop destination modifier.
Use the ItemID and CollectionID types of your reorderContainer(for:in:isEnabled:move:) modifier to look up the destination value.
This value can be nil, if the container was unable to determine a placement for the items. This can happen if the user drags items into the destination but does not interact with any of the container items to determine a concrete position. You should still accept these items into the container. In this example, those values are appended to the end of the collection:
struct ContentView: View {
@State var contacts: [Contact] = []
var body: some View {
VStack {
ForEach(contacts) { contact in
ContactView(contact)
}
.reorderable()
}
.reorderContainer(for: Contact.ID.self) { difference in
difference.apply(to: &contacts)
}
.dragContainer(for: Contact.self) { itemID in
contacts.first { $0.id == itemID }.map { [$0] } ?? []
}
.dropDestination(for: Contact.self) { items, session in
if let destinationIndex = session.reorderDestination(
for: Contact.ID.self)?.index(in: contacts)
{
contacts.insert(
contentsOf: items, at: destinationIndex)
} else {
contacts.append(contentsOf: items)
}
}
}
}
Parameters
item- The type of reorderable items in the container.
collectionID- The identifier type for collections in your container.
func
DropSession.reorderDestination
NewiOSmacOSnonisolated public func reorderDestination<Item, ItemID, CollectionID>(for item: Item.Type, itemID: KeyPath<Item, ItemID>, in collectionID: CollectionID.Type = ReorderableSingleCollectionIdentifier.self) -> ReorderDifference<ItemID, CollectionID>.Destination?
Provides the destination value of a reordering operation that occurred in the container associated with this drop destination modifier.
Use the ItemID and CollectionID types of your reorderContainer(for:in:isEnabled:move:) modifier to look up the destination value.
This value can be nil, if the container was unable to determine a placement for the items. This can happen if the user drags items into the destination but does not interact with any of the container items to determine a concrete position. You should still accept these items into the container. In this example, those values are appended to the end of the collection:
struct ContentView: View {
@State var accounts: [Account] = []
var body: some View {
VStack {
ForEach(accounts, id: \.uuid) { account in
AccountView(account)
}
.reorderable()
}
.reorderContainer(for: Account.self, itemID: \.uuid) {
(difference) in
difference.apply(to: &accounts)
}
.dragContainer(for: Account.self) { userIDs in
findAccounts(ids: userIDs)
}
.dropDestination(for: Account.self) { items, session in
if let destinationIndex = session.reorderDestination(
for: Account.self, itemID: \.uuid)?.index(
in: accounts)
{
accounts.insert(
contentsOf: items, at: destinationIndex)
} else {
accounts.append(contentsOf: items)
}
}
}
}
Parameters
item- The type of reorderable items in the container.
collectionID- The identifier type for collections in your container.
func
DynamicViewContent.reorderable
NewiOSmacOSwatchOSnonisolated public func reorderable() -> some DynamicViewContent<Self.Data>
Enables the views of this content to be reordered when used within the scope of a reorderContainer(for:in:isEnabled:move:) modifier.
Declare this modifier on DynamicViewContent within a reorderable container to allow your users to reorder the items in the content using a system drag gesture.
Provide a collection identifier when you have multiple collections in the container and need to uniquely refer to each one. If your container only has a single collection, you can use the default identifier.
This example shows a list of landmarks. Items can be moved within the view's underlying collection.
struct ContentView: View {
@State private var landmarks: [Landmark] = []
var body: some View {
VStack {
ForEach(landmarks) { landmark in
LandmarkView(landmark)
}
.reorderable()
}
.reorderContainer(for: Landmark.self) { difference in
difference.apply(to: &landmarks)
}
}
}
func
DynamicViewContent.reorderable
NewiOSmacOSwatchOSnonisolated public func reorderable(collectionID: some Hashable & Sendable) -> some DynamicViewContent<Self.Data>
Enables the views of this content to be reordered when used within the scope of a reorderContainer(for:in:isEnabled:move:) modifier.
Declare this modifier on DynamicViewContent within a reorderable container to allow your users to reorder the items in the content using a system drag gesture.
Provide a collection identifier when you have multiple collections in the container and need to uniquely refer to each one. If your container only has a single collection, you can use the default identifier.
This example shows a sectioned list of reminders:
struct ContentView: View {
@State private var model = ReminderModel()
var body: some View {
List {
ForEach(model.sections) { section in
Section(section.name) {
ForEach(section.reminders) { reminder in
ReminderView(reminder)
}
.reorderable(collectionID: section.id)
}
}
}
.reorderContainer(
for: Reminder.self, in: ReminderModel.Section.ID.self
) { difference in
model.apply(difference: difference)
}
}
}
Parameters
collectionID- The identifier that represents this collection. Its value is used in the destination value when reordering.
typealias
ExternalNonInteractiveAccessory.Body
NewiOSpublic typealias Body = some SceneAccessoryContent
The type of content representing the body of this scene accessory content.
typealias
Optional.Body
NewiOSpublic typealias Body = Never
The type of content representing the body of this scene accessory content.
init
Preview.init
NewmacOSpublic init<T>(_ name: String? = nil, traits: PreviewTrait<Preview.ViewTraits>..., arguments: [T], @ContentBuilder body: @escaping @MainActor (T) -> any View)
Creates a group of previews of a SwiftUI view.
A preview macro expands into a declaration that calls this initializer. Don't use this initializer directly.
Parameters
name- An optional display name for the preview.
traits- An optional list of traits to customize the preview.
arguments- An array of arguments to pass into
body. body- A closure that maps an argument to a SwiftUI view to preview.
func
TabContent.defaultSectionExpansion
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func defaultSectionExpansion(_ expansion: TabSectionExpansion) -> some TabContent<Self.TabValue>
Sets the default expansion state for the section containing this tab when displayed in the sidebar.
Use this modifier to control whether a tab section starts expanded or collapsed in the sidebar. The user can manually change the expansion state, and subsequent user interactions take precedence over this default.
This modifier has no effect in contexts where sections are not collapsible — for example, on platforms that do not present a collapsible sidebar, or when automatic is supplied.
TabView {
TabSection("Library") {
Tab("Songs", systemImage: "music.note") {
SongsView()
}
Tab("Albums", systemImage: "square.stack") {
AlbumsView()
}
}
TabSection("Archive") {
Tab("Old Playlists", systemImage: "archivebox") {
ArchiveView()
}
Tab("Deleted", systemImage: "trash") {
DeletedView()
}
}
.defaultSectionExpansion(.collapsed)
}
.tabViewStyle(.sidebarAdaptable)
Parameters
expansion- The default expansion behavior for the containing section. The default is
automatic.
var
TabRole.prominent
NewiOSmacOStvOSvisionOSwatchOSpublic static var prominent: TabRole { get }
The prominent role.
A tab role that provides prominent visual treatment to one of the tabs in supported tab bars. Only one tab can receive the prominent treatment. When there are no tabs with an explicit .prominent role, then a .search role tab may receive the prominent visual treatment by default.
let
ToolbarItemPlacement.topBarPinnedTrailing
NewiOSpublic static let topBarPinnedTrailing: ToolbarItemPlacement
A placement that pins the item to the trailing edge of the toolbar.
Pinned items only move to the overflow menu when search is active and there isn't enough room.
On iOS and visionOS, the top bar is the navigation bar.
let
ToolbarItemVisibilityPriority.high
NewiOSpublic static let high: ToolbarItemVisibilityPriority
A priority that keeps the item in the toolbar longer than items with the default or low priority.
Use for frequently used actions that need to stay visible as the toolbar shrinks.
init
ToolbarItemVisibilityPriority.init
NewiOSmacOSpublic init(lowerThan other: ToolbarItemVisibilityPriority)
Creates a priority lower than the specified value.
The priority is lower than other but doesn't cross below the next lower system priority. For example, ToolbarItemVisibilityPriority(lowerThan: .high) returns a value that is less than .high but greater than .automatic.
Priorities created with the same base value are equal:
let x = ToolbarItemVisibilityPriority(lowerThan: .high)
let y = ToolbarItemVisibilityPriority(lowerThan: .high)
x == y // true
init
ToolbarItemVisibilityPriority.init
NewiOSmacOSpublic init(higherThan other: ToolbarItemVisibilityPriority)
Creates a priority higher than the specified value.
The priority is higher than other but doesn't cross above the next higher system priority. For example, ToolbarItemVisibilityPriority(higherThan: .high) returns a value that is greater than .high.
Priorities created with the same base value are equal:
let x = ToolbarItemVisibilityPriority(higherThan: .high)
let y = ToolbarItemVisibilityPriority(higherThan: .high)
x == y // true
let
ToolbarItemVisibilityPriority.low
NewiOSpublic static let low: ToolbarItemVisibilityPriority
A priority that moves the item to the overflow menu before items with the default or high priority.
Use for secondary actions, such as archive or delete, that don't need persistent visibility in the toolbar.
typealias
ToolbarOverflowMenu.Body
NewiOSpublic typealias Body = Never
The type of content representing the body of this toolbar content.
var
ToolbarPlacement.statusBar
NewiOSpublic static var statusBar: ToolbarPlacement { get }
The system status bar.
Use with toolbarVisibility(_:for:) to hide the status bar, or with toolbarColorScheme(_:for:) to specify the preferred status bar style.
content
.toolbarVisibility(
hideStatusBar ? .hidden : .automatic,
for: .statusBar)
// use light status bar on a dark background
.toolbarColorScheme(.dark, for: .statusBar)
Using this placement with other toolbar customization APIs has no effect.
typealias
TupleContent.Body
NewiOSmacOStvOSwatchOSpublic typealias Body = Never
The type of content representing the body of this scene accessory content.
init
UISceneSessionActivationRequest.init
NewtvOSpublic init?<D>(hostingDelegateClass: D.Type) where D : UIHostingSceneDelegate
Creates a UISceneSessionActivationRequest customized to open a SwiftUI scene.
The first scene declared in the rootScene property of your hosting delegate class will be activated by this request.
class HostingSceneDelegate: UIHostingSceneDelegate {
static var rootScene: some Scene {
WindowGroup() {
ContentView()
}
}
}
let request = UISceneSessionActivationRequest(
hostingDelegateClass: HostingSceneDelegate.self
)
UIApplication.shared.activateSceneSession(for: request)
When a UIScene is activated using this request object, its configuration is managed by SwiftUI. You will not see a call to your app delegate's application(_:configurationForConnecting:options:) method.
An instance of the provided hosting delegate class will be created by SwiftUI and receive lifecycle callbacks for the associated scene.
Parameters
hostingDelegateClass- A Class type that conforms to
UIHostingSceneDelegate.
init
UISceneSessionActivationRequest.init
NewtvOSpublic init?<D>(hostingDelegateClass: D.Type, id: String) where D : UIHostingSceneDelegate
Creates a UISceneSessionActivationRequest customized to open a SwiftUI scene with the given identifier.
The specified scene must be declared in the rootScene property of your hosting delegate class. The initializer will fail if no scene with the specified identifier is defined.
class HostingSceneDelegate: UIHostingSceneDelegate {
static var rootScene: some Scene {
WindowGroup(id: "swiftui-window") {
ContentView()
}
}
}
if let requestWithID = UISceneSessionActivationRequest(
hostingDelegateClass: HostingSceneDelegate.self,
id: "swiftui-window"
) {
UIApplication.shared.activateSceneSession(for: requestWithID)
}
When a UIScene is activated using this request object, its configuration is managed by SwiftUI. You will not see a call to your app delegate's application(_:configurationForConnecting:options:) method.
An instance of the provided hosting delegate class will be created by SwiftUI and receive lifecycle callbacks for the associated scene.
Parameters
hostingDelegateClass- A Class type that conforms to
UIHostingSceneDelegate. id- A string matching the
id of one of the scenes declared in the sceneRepresentation's content.
init
UISceneSessionActivationRequest.init
NewtvOSpublic init?<H, D>(hostingDelegateClass: H.Type, value: D) where H : UIHostingSceneDelegate, D : Decodable, D : Encodable, D : Hashable
Creates a UISceneSessionActivationRequest customized to open a SwiftUI scene with a presented value.
The specified scene must be declared in the rootScene property of your hosting delegate class. The initializer will fail if no scene with the specified identifier is defined.
class HostingSceneDelegate: UIHostingSceneDelegate {
static var rootScene: some Scene {
WindowGroup(for: FavoriteNumber.self) { $value in
ContentView(favoriteNumber: $value)
}
}
}
if let requestWithData = UISceneSessionActivationRequest(
hostingDelegateClass: HostingSceneDelegate.self,
value: FavoriteNumber(13)
) {
UIApplication.shared.activateSceneSession(for: requestWithData)
}
When a UIScene is activated using this request object, its configuration is managed by SwiftUI. You will not see a call to your app delegate's application(_:configurationForConnecting:) method.
An instance of the provided hosting delegate class will be created by SwiftUI and receive lifecycle callbacks for the associated scene.
Parameters
hostingDelegateClass- A Class type that conforms to
UIHostingSceneDelegate. value- The data to be presented in the scene.
init
UISceneSessionActivationRequest.init
NewtvOSpublic init?<H, D>(hostingDelegateClass: H.Type, id: String, value: D) where H : UIHostingSceneDelegate, D : Decodable, D : Encodable, D : Hashable
Creates a UISceneSessionActivationRequest customized to open a SwiftUI scene with the given identifier and presented value.
The specified scene must be declared in the rootScene property of your hosting delegate class. The initializer will fail if no scene with the specified identifier is defined.
class HostingSceneDelegate: UIHostingSceneDelegate {
static var rootScene: some Scene {
WindowGroup(id: "window", for: FavoriteNumber.self) { $value in
ContentView(favoriteNumber: $value)
}
}
}
if let activationWithIDAndData = UISceneSessionActivationRequest(
hostingDelegateClass: HostingSceneDelegate.self,
id: "window", value: FavoriteNumber(13)
) {
UIApplication.shared.activateSceneSession(for: activationWithIDAndData)
}
When a UIScene is activated using this request object, its configuration is managed by SwiftUI. You will not see a call to your app delegate's application(_:configurationForConnecting:) method.
An instance of the provided hosting delegate class will be created by SwiftUI and receive lifecycle callbacks for the associated scene.
Parameters
hostingDelegateClass- A Class type that conforms to
UIHostingSceneDelegate. id- A string matching the
id of one of the scenes declared in the sceneRepresentation's content. value- The data to be presented in the scene.
func
View.alert
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func alert<A, T>(_ titleKey: LocalizedStringKey, item data: Binding<T?>, @ContentBuilder actions: (T) -> A) -> some View where A : View
Presents an alert using the given data to produce the alert's content and a localized string key for a title.
For the alert to appear, data must not be nil. The data should not change after the presentation occurs. Any changes that you make after the presentation occurs are ignored.
Use this method when you need to populate the fields of an alert with content from a data source. The example below shows a custom data source, SaveDetails, that provides data to populate the alert:
struct SaveDetails: Identifiable {
let name: String
let error: String
let id = UUID()
}
struct SaveButton: View {
@State private var details: SaveDetails?
var body: some View {
Button("Save") {
details = model.save()
}
.alert(
"Save failed.",
item: $details
) { details in
Button(role: .destructive) {
// Handle the deletion.
} label: {
Text("Delete \(details.name)")
}
Button("Retry") {
// Handle the retry action.
}
}
}
}
This modifier creates a Text view for the title on your behalf, and treats the localized key similar to init(_:tableName:bundle:comment:). See Text for more information about localizing strings.
All actions in an alert dismiss the alert after the action runs. The default button is shown with greater prominence. You can influence the default button by assigning it the defaultAction keyboard shortcut.
The system may reorder the buttons based on their role and prominence.
If no actions are present, the system includes a standard "OK" action. No default cancel action is provided. If you want to show a cancel action, use a button with a role of cancel.
On iOS, tvOS, and watchOS, alerts only support controls with labels that are Text. Passing any other type of view results in the content being omitted.
Parameters
titleKey- The key for the localized string that describes the title of the alert.
data- A binding to optional source of truth for the alert. The system presents the alert when the binding's value is non-nil. When the user presses or taps one of the alert's actions, the system sets this value to
nil and dismisses. The system passes the contents to the modifier's closures. You use this data to populate the fields of an alert that you create that the system displays to the user. actions- A
ContentBuilder returning the alert's actions given the currently available data.
func
View.alert
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func alert<A, T>(_ titleResource: LocalizedStringResource, item data: Binding<T?>, @ContentBuilder actions: (T) -> A) -> some View where A : View
Presents an alert using the given data to produce the alert's content and a localized string resource for a title.
For the alert to appear, data must not be nil. The data should not change after the presentation occurs. Any changes that you make after the presentation occurs are ignored.
Use this method when you need to populate the fields of an alert with content from a data source. The example below shows a custom data source, SaveDetails, that provides data to populate the alert:
struct SaveDetails: Identifiable {
let name: String
let error: String
let id = UUID()
}
struct SaveButton: View {
@State private var details: SaveDetails?
var body: some View {
Button("Save") {
details = model.save()
}
.alert(
"Save failed.",
item: $details
) { details in
Button(role: .destructive) {
// Handle the deletion.
} label: {
Text("Delete \(details.name)")
}
Button("Retry") {
// Handle the retry action.
}
}
}
}
This modifier creates a Text view for the title on your behalf. See Text for more information about localizing strings.
All actions in an alert dismiss the alert after the action runs. The default button is shown with greater prominence. You can influence the default button by assigning it the defaultAction keyboard shortcut.
The system may reorder the buttons based on their role and prominence.
If no actions are present, the system includes a standard "OK" action. No default cancel action is provided. If you want to show a cancel action, use a button with a role of cancel.
On iOS, tvOS, and watchOS, alerts only support controls with labels that are Text. Passing any other type of view results in the content being omitted.
Parameters
titleResource- Text resource for the localized string that describes the title of the alert.
data- A binding to optional source of truth for the alert. The system presents the alert when the binding's value is non-nil. When the user presses or taps one of the alert's actions, the system sets this value to
nil and dismisses. The system passes the contents to the modifier's closures. You use this data to populate the fields of an alert that you create that the system displays to the user. actions- A
ContentBuilder returning the alert's actions given the currently available data.
func
View.alert
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func alert<S, A, T>(_ title: S, item data: Binding<T?>, @ContentBuilder actions: (T) -> A) -> some View where S : StringProtocol, A : View
Presents an alert using the given data to produce the alert's content and a string variable as a title.
For the alert to appear, data must not be nil. The data should not change after the presentation occurs. Any changes that you make after the presentation occurs are ignored.
Use this method when you need to populate the fields of an alert with content from a data source. The example below shows a custom data source, SaveDetails, that provides data to populate the alert:
struct SaveDetails: Identifiable {
let name: String
let error: String
let id = UUID()
}
struct SaveButton: View {
@State private var details: SaveDetails?
let alertTitle: String = "Save failed."
var body: some View {
Button("Save") {
details = model.save()
}
.alert(
alertTitle,
item: $details
) { details in
Button(role: .destructive) {
// Handle the deletion.
} label: {
Text("Delete \(details.name)")
}
Button("Retry") {
// Handle the retry action.
}
}
}
}
All actions in an alert dismiss the alert after the action runs. The default button is shown with greater prominence. You can influence the default button by assigning it the defaultAction keyboard shortcut.
The system may reorder the buttons based on their role and prominence.
If no actions are present, the system includes a standard "OK" action. No default cancel action is provided. If you want to show a cancel action, use a button with a role of cancel.
On iOS, tvOS, and watchOS, alerts only support controls with labels that are Text. Passing any other type of view results in the content being omitted.
Parameters
title- A text string used as the title of the alert.
data- A binding to optional source of truth for the alert. The system presents the alert when the binding's value is non-nil. When the user presses or taps one of the alert's actions, the system sets this value to
nil and dismisses. The system passes the contents to the modifier's closures. You use this data to populate the fields of an alert that you create that the system displays to the user. actions- A
ContentBuilder returning the alert's actions given the currently available data.
func
View.alert
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func alert<A, T>(_ title: Text, item data: Binding<T?>, @ContentBuilder actions: (T) -> A) -> some View where A : View
Presents an alert using the given data to produce the alert's content and a text view as a title.
For the alert to appear, data must not be nil. The data should not change after the presentation occurs. Any changes that you make after the presentation occurs are ignored.
Use this method when you need to populate the fields of an alert with content from a data source. The example below shows a custom data source, SaveDetails, that provides data to populate the alert:
struct SaveDetails: Identifiable {
let name: String
let error: String
let id = UUID()
}
struct SaveButton: View {
@State private var details: SaveDetails?
let alertTitle: String = "Save failed."
var body: some View {
Button("Save") {
details = model.save()
}
.alert(
Text(alertTitle),
item: $details
) { details in
Button(role: .destructive) {
// Handle the deletion.
} label: {
Text("Delete \(details.name)")
}
Button("Retry") {
// Handle the retry action.
}
}
}
}
All actions in an alert dismiss the alert after the action runs. The default button is shown with greater prominence. You can influence the default button by assigning it the defaultAction keyboard shortcut.
The system may reorder the buttons based on their role and prominence.
If no actions are present, the system includes a standard "OK" action. No default cancel action is provided. If you want to show a cancel action, use a button with a role of cancel.
On iOS, tvOS, and watchOS, alerts only support controls with labels that are Text. Passing any other type of view results in the content being omitted.
Parameters
title- the title of the alert.
data- A binding to optional source of truth for the alert. The system presents the alert when the binding's value is non-nil. When the user presses or taps one of the alert's actions, the system sets this value to
nil and dismisses. The system passes the contents to the modifier's closures. You use this data to populate the fields of an alert that you create that the system displays to the user. actions- A
ContentBuilder returning the alert's actions given the currently available data.
func
View.alert
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func alert<A, M, T>(_ titleKey: LocalizedStringKey, item data: Binding<T?>, @ContentBuilder actions: (T) -> A, @ContentBuilder message: (T) -> M) -> some View where A : View, M : View
Presents an alert with a message using the given data to produce the alert's content and a localized string key for a title.
For the alert to appear, data must not be nil. The data should not change after the presentation occurs. Any changes that you make after the presentation occurs are ignored.
Use this method when you need to populate the fields of an alert with content from a data source. The example below shows a custom data source, SaveDetails, that provides data to populate the alert:
struct SaveDetails: Identifiable {
let name: String
let error: String
let id = UUID()
}
struct SaveButton: View {
@State private var details: SaveDetails?
var body: some View {
Button("Save") {
details = model.save(didError: $didError)
}
.alert(
"Save failed.",
item: $details
) { details in
Button(role: .destructive) {
// Handle the deletion.
} label: {
Text("Delete \(details.name)")
}
Button("Retry") {
// Handle the retry action.
}
} message: { details in
Text(details.error)
}
}
}
This modifier creates a Text view for the title on your behalf, and treats the localized key similar to init(_:tableName:bundle:comment:). See Text for more information about localizing strings.
All actions in an alert dismiss the alert after the action runs. The default button is shown with greater prominence. You can influence the default button by assigning it the defaultAction keyboard shortcut.
The system may reorder the buttons based on their role and prominence.
If no actions are present, the system includes a standard "OK" action. No default cancel action is provided. If you want to show a cancel action, use a button with a role of cancel.
On iOS, tvOS, and watchOS, alerts only support controls with labels that are Text. Passing any other type of view results in the content being omitted.
Only unstyled text is supported for the message.
Parameters
titleKey- The key for the localized string that describes the title of the alert.
data- A binding to optional source of truth for the alert. The system presents the alert when the binding's value is non-nil. When the user presses or taps one of the alert's actions, the system sets this value to
nil and dismisses. The system passes the contents to the modifier's closures. You use this data to populate the fields of an alert that you create that the system displays to the user. actions- A
ContentBuilder returning the alert's actions given the currently available data. message- A
ContentBuilder returning the message for the alert given the currently available data.
func
View.alert
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func alert<A, M, T>(_ titleResource: LocalizedStringResource, item data: Binding<T?>, @ContentBuilder actions: (T) -> A, @ContentBuilder message: (T) -> M) -> some View where A : View, M : View
Presents an alert with a message using the given data to produce the alert's content and a localized string resource for a title.
For the alert to appear, data must not be nil. The data should not change after the presentation occurs. Any changes that you make after the presentation occurs are ignored.
Use this method when you need to populate the fields of an alert with content from a data source. The example below shows a custom data source, SaveDetails, that provides data to populate the alert:
struct SaveDetails: Identifiable {
let name: String
let error: String
let id = UUID()
}
struct SaveButton: View {
@State private var details: SaveDetails?
var body: some View {
Button("Save") {
details = model.save(didError: $didError)
}
.alert(
"Save failed.",
item: $details
) { details in
Button(role: .destructive) {
// Handle the deletion.
} label: {
Text("Delete \(details.name)")
}
Button("Retry") {
// Handle the retry action.
}
} message: { details in
Text(details.error)
}
}
}
This modifier creates a Text view for the title on your behalf. See Text for more information about localizing strings.
All actions in an alert dismiss the alert after the action runs. The default button is shown with greater prominence. You can influence the default button by assigning it the defaultAction keyboard shortcut.
The system may reorder the buttons based on their role and prominence.
If no actions are present, the system includes a standard "OK" action. No default cancel action is provided. If you want to show a cancel action, use a button with a role of cancel.
On iOS, tvOS, and watchOS, alerts only support controls with labels that are Text. Passing any other type of view results in the content being omitted.
Only unstyled text is supported for the message.
Parameters
titleResource- Text resource for the localized string that describes the title.
data- A binding to optional source of truth for the alert. The system presents the alert when the binding's value is non-nil. When the user presses or taps one of the alert's actions, the system sets this value to
nil and dismisses. The system passes the contents to the modifier's closures. You use this data to populate the fields of an alert that you create that the system displays to the user. actions- A
ContentBuilder returning the alert's actions given the currently available data. message- A
ContentBuilder returning the message for the alert given the currently available data.
func
View.alert
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func alert<S, A, M, T>(_ title: S, item data: Binding<T?>, @ContentBuilder actions: (T) -> A, @ContentBuilder message: (T) -> M) -> some View where S : StringProtocol, A : View, M : View
Presents an alert with a message using the given data to produce the alert's content and a string variable as a title.
For the alert to appear, data must not be nil. The data should not change after the presentation occurs. Any changes that you make after the presentation occurs are ignored.
Use this method when you need to populate the fields of an alert with content from a data source. The example below shows a custom data source, SaveDetails, that provides data to populate the alert:
struct SaveDetails: Identifiable {
let name: String
let error: String
let id = UUID()
}
struct SaveButton: View {
@State private var details: SaveDetails?
let alertTitle: String = "Save failed."
var body: some View {
Button("Save") {
details = model.save(didError: $didError)
}
.alert(
alertTitle,
item: $details
) { details in
Button(role: .destructive) {
// Handle the deletion.
} label: {
Text("Delete \(details.name)")
}
Button("Retry") {
// Handle the retry action.
}
} message: { details in
Text(details.error)
}
}
}
All actions in an alert dismiss the alert after the action runs. The default button is shown with greater prominence. You can influence the default button by assigning it the defaultAction keyboard shortcut.
The system may reorder the buttons based on their role and prominence.
If no actions are present, the system includes a standard "OK" action. No default cancel action is provided. If you want to show a cancel action, use a button with a role of cancel.
On iOS, tvOS, and watchOS, alerts only support controls with labels that are Text. Passing any other type of view results in the content being omitted.
Only unstyled text is supported for the message.
Parameters
title- A text string used as the title of the alert.
data- A binding to optional source of truth for the alert. The system presents the alert when the binding's value is non-nil. When the user presses or taps one of the alert's actions, the system sets this value to
nil and dismisses. The system passes the contents to the modifier's closures. You use this data to populate the fields of an alert that you create that the system displays to the user. actions- A
ContentBuilder returning the alert's actions given the currently available data. message- A
ContentBuilder returning the message for the alert given the currently available data.
func
View.alert
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func alert<E, A>(error: Binding<E?>, @ContentBuilder actions: () -> A) -> some View where E : Error, A : View
Presents an alert when an error is present.
In the example below, a form conditionally presents an alert depending upon the value of an error. When the error value isn't nil, the system presents an alert with an "OK" action.
The title of the alert is inferred from the error's errorDescription if the error is a LocalizedError; otherwise it will be localizedDescription.
struct TicketPurchase: View {
@State private var error: TicketPurchaseError? = nil
var body: some View {
TicketForm(error: $error)
.alert(error: $error) {
Button("OK") {
// Handle acknowledgement.
}
}
}
}
All actions in an alert dismiss the alert after the action runs. The default button is shown with greater prominence. You can influence the default button by assigning it the defaultAction keyboard shortcut.
The system may reorder the buttons based on their role and prominence.
If no actions are present, the system includes a standard "OK" action. No default cancel action is provided. If you want to show a cancel action, use a button with a role of cancel.
On iOS, tvOS, and watchOS, alerts only support controls with labels that are Text. Passing any other type of view results in the content being omitted.
This modifier creates a Text view for the title on your behalf, and treats the localized key similar to init(_:tableName:bundle:comment:). See Text for more information about localizing strings.
Parameters
error- A binding to an optional localized Error. The system presents the alert when the binding's value is non-nil, and uses the error to generate the alert's title. When the user presses or taps one of the alert's actions, the system sets this value to
nil and dismisses. If the error is a LocalizedError, its errorDescription will be used as the title, otherwise, the title will be localizedDescription. actions- A
ContentBuilder returning the alert's actions.
func
View.alert
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func alert<E, A, M>(error: Binding<E?>, @ContentBuilder actions: (E) -> A, @ContentBuilder message: (E) -> M) -> some View where E : Error, A : View, M : View
Presents an alert with a message when an error is present.
In the example below, a form conditionally presents an alert depending upon the value of an error. When the error value isn't nil, the system presents an alert with an "OK" action.
The title of the alert is inferred from the error's errorDescription if the error is a LocalizedError; otherwise it will be localizedDescription.
struct TicketPurchase: View {
@State private var error: TicketPurchaseError? = nil
var body: some View {
TicketForm(error: $error)
.alert(error: $error) { _ in
Button("OK") {
// Handle acknowledgement.
}
} message: { error in
Text(error.recoverySuggestion ?? "Try again later.")
}
}
}
All actions in an alert dismiss the alert after the action runs. The default button is shown with greater prominence. You can influence the default button by assigning it the defaultAction keyboard shortcut.
The system may reorder the buttons based on their role and prominence.
If no actions are present, the system includes a standard "OK" action. No default cancel action is provided. If you want to show a cancel action, use a button with a role of cancel.
On iOS, tvOS, and watchOS, alerts only support controls with labels that are Text. Passing any other type of view results in the content being omitted.
This modifier creates a Text view for the title on your behalf, and treats the localized key similar to init(_:tableName:bundle:comment:). See Text for more information about localizing strings.
Parameters
error- A binding to an optional Error. The system presents the alert when the binding's value is non-nil, and uses the error to generate the alert's title. When the user presses or taps one of the alert's actions, the system sets this value to
nil and dismisses. The system passes the error to the modifier's closures. You use this data to populate the fields of an alert that the system displays to the user. If the error is a LocalizedError, its errorDescription will be used as the title, otherwise, the title will be localizedDescription. actions- A
ContentBuilder returning the alert's actions. message- A
ContentBuilder returning the message for the alert given the current error.
func
View.asyncImageURLSession
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func asyncImageURLSession(_ urlSession: URLSession) -> some View
Put a URLSession instance for in the View's environment. AsyncImage will use this instance to perform data tasks to fetch image data.
Parameters
urlSession- An instance of
URLSession with which AsyncImages uses to perform image download data tasks.
func
View.confirmationDialog
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func confirmationDialog<A, T>(_ titleKey: LocalizedStringKey, item data: Binding<T?>, titleVisibility: Visibility = .automatic, @ContentBuilder actions: (T) -> A) -> some View where A : View
Presents a confirmation dialog using data to produce the dialog's content and a localized string key for the title.
Parameters
titleKey- The key for the localized string that describes the title of the dialog.
data- A binding to optional source of truth for the confirmation dialog. The system presents the dialog when the binding's value is non-nil. When the user presses or taps the dialog's default action button, the system sets this value to
nil and dismisses. The system passes the contents to the modifier's closures. You use this data to populate the fields of a confirmation dialog that you create that the system displays to the user. titleVisibility- The visibility of the dialog's title. The default value is
automatic. actions- A
ContentBuilder returning the dialog's actions given the currently available data.
func
View.confirmationDialog
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func confirmationDialog<A, T>(_ titleResource: LocalizedStringResource, item data: Binding<T?>, titleVisibility: Visibility = .automatic, @ContentBuilder actions: (T) -> A) -> some View where A : View
Presents a confirmation dialog using data to produce the dialog's content and a localized string resource for the title.
Parameters
titleResource- Text resource for the localized string that describes the title of the dialog.
data- A binding to optional source of truth for the confirmation dialog. The system presents the dialog when the binding's value is non-nil. When the user presses or taps the dialog's default action button, the system sets this value to
nil and dismisses. The system passes the contents to the modifier's closures. You use this data to populate the fields of a confirmation dialog that you create that the system displays to the user. titleVisibility- The visibility of the dialog's title. The default value is
automatic. actions- A
ContentBuilder returning the dialog's actions given the currently available data.
func
View.confirmationDialog
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func confirmationDialog<S, A, T>(_ title: S, item data: Binding<T?>, titleVisibility: Visibility = .automatic, @ContentBuilder actions: (T) -> A) -> some View where S : StringProtocol, A : View
Presents a confirmation dialog using data to produce the dialog's content and a string variable for the title.
Parameters
title- A text string used as the title of the dialog.
data- A binding to optional source of truth for the confirmation dialog. The system presents the dialog when the binding's value is non-nil. When the user presses or taps the dialog's default action button, the system sets this value to
nil and dismisses. The system passes the contents to the modifier's closures. You use this data to populate the fields of a confirmation dialog that you create that the system displays to the user. titleVisibility- The visibility of the dialog's title. The default value is
automatic. actions- A
ContentBuilder returning the dialog's actions given the currently available data.
func
View.confirmationDialog
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func confirmationDialog<A, T>(_ title: Text, item data: Binding<T?>, titleVisibility: Visibility = .automatic, @ContentBuilder actions: (T) -> A) -> some View where A : View
Presents a confirmation dialog using data to produce the dialog's content and a text view for the title.
Parameters
title- the title of the dialog.
data- A binding to optional source of truth for the confirmation dialog. The system presents the dialog when the binding's value is non-nil. When the user presses or taps the dialog's default action button, the system sets this value to
nil and dismisses. The system passes the contents to the modifier's closures. You use this data to populate the fields of a confirmation dialog that you create that the system displays to the user. titleVisibility- The visibility of the dialog's title. The default value is
automatic. actions- A
ContentBuilder returning the dialog's actions given the currently available data.
func
View.confirmationDialog
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func confirmationDialog<A, M, T>(_ titleKey: LocalizedStringKey, item data: Binding<T?>, titleVisibility: Visibility = .automatic, @ContentBuilder actions: (T) -> A, @ContentBuilder message: (T) -> M) -> some View where A : View, M : View
Presents a confirmation dialog with a message using data to produce the dialog's content and a localized string key for the title.
Parameters
titleKey- The key for the localized string that describes the title of the dialog.
data- A binding to optional source of truth for the confirmation dialog. The system presents the dialog when the binding's value is non-nil. When the user presses or taps the dialog's default action button, the system sets this value to
nil and dismisses. The system passes the contents to the modifier's closures. You use this data to populate the fields of a confirmation dialog that you create that the system displays to the user. titleVisibility- The visibility of the dialog's title. The default value is
automatic. actions- A
ContentBuilder returning the dialog's actions given the currently available data. message- A
ContentBuilder returning the message for the dialog given the currently available data.
func
View.confirmationDialog
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func confirmationDialog<A, M, T>(_ titleResource: LocalizedStringResource, item data: Binding<T?>, titleVisibility: Visibility = .automatic, @ContentBuilder actions: (T) -> A, @ContentBuilder message: (T) -> M) -> some View where A : View, M : View
Presents a confirmation dialog with a message using data to produce the dialog's content and a localized string resource for the title.
the title of the dialog.
- data: A binding to optional source of truth for the confirmation
dialog. The system presents the dialog when the binding's value is
non-nil. When the user presses or taps the dialog's default action
button, the system sets this value to `nil` and dismisses. The
system passes the contents to the modifier's closures. You use this
data to populate the fields of a confirmation dialog that you create
that the system displays to the user.
- titleVisibility: The visibility of the dialog's title. The default
value is ``Visibility/automatic``.
- actions: A
ContentBuilder returning the dialog's actions given the
currently available data.
- message: A
ContentBuilder returning the message for the dialog given
the currently available data.
Parameters
titleResource- Text resource for the localized string that describes
func
View.confirmationDialog
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func confirmationDialog<S, A, M, T>(_ title: S, item data: Binding<T?>, titleVisibility: Visibility = .automatic, @ContentBuilder actions: (T) -> A, @ContentBuilder message: (T) -> M) -> some View where S : StringProtocol, A : View, M : View
Presents a confirmation dialog with a message using data to produce the dialog's content and a string variable for the title.
Parameters
title- A text string used as the title of the dialog.
data- A binding to optional source of truth for the confirmation dialog. The system presents the dialog when the binding's value is non-nil. When the user presses or taps the dialog's default action button, the system sets this value to
nil and dismisses. The system passes the contents to the modifier's closures. You use this data to populate the fields of a confirmation dialog that you create that the system displays to the user. titleVisibility- The visibility of the dialog's title. The default value is
automatic. actions- A
ContentBuilder returning the dialog's actions given the currently available data. message- A
ContentBuilder returning the message for the dialog given the currently available data.
func
View.confirmationDialog
NewiOSmacOStvOSvisionOSwatchOSnonisolated public func confirmationDialog<A, M, T>(_ title: Text, item data: Binding<T?>, titleVisibility: Visibility = .automatic, @ContentBuilder actions: (T) -> A, @ContentBuilder message: (T) -> M) -> some View where A : View, M : View
Presents a confirmation dialog with a message using data to produce the dialog's content and a text view for the message.
Parameters
title- the title of the dialog.
data- A binding to optional source of truth for the confirmation dialog. The system presents the dialog when the binding's value is non-nil. When the user presses or taps the dialog's default action button, the system sets this value to
nil and dismisses. The system passes the contents to the modifier's closures. You use this data to populate the fields of a confirmation dialog that you create that the system displays to the user. titleVisibility- The visibility of the dialog's title. The default value is
automatic. actions- A
ContentBuilder returning the dialog's actions given the currently available data. message- A
ContentBuilder returning the message for the dialog given the currently available data.
func
View.copyable
NewiOSnonisolated public func copyable<T>(_ payload: @autoclosure @escaping () -> [T]) -> some View where T : Transferable
Specifies a list of items to copy in response to the system's Copy command.
Use this modifier to specify one or more items that the system copies to the Clipboard when someone issues a Copy command while the modified view has focus. People issue a Copy command by choosing Edit > Copy from the app's menu, or by using the Command-C keyboard shortcut. The system enables the Copy command for your app when it detects copyable content.
For example, the following code enables people to copy all of the strings that they select in a List:
struct CopyableExample: View {
let strings = ["Alpha", "Beta", "Gamma"]
@State private var selection: Set<String> = []
var body: some View {
List(strings, id: \.self, selection: $selection) {
Text($0)
}
.copyable(Array(selection))
}
}
The command copies each item's representation as specified by the item's conformance to the <doc://com.apple.documentation/documentation/coretransferable/transferable> protocol. The above example records selection using each list item's corresponding string, and strings conform to the Transferable protocol by default. For more complex cases, you might need to take additional steps.
For example, the following code displays colors composed from a list of Item instances that contain both a color and its name, as well as an identifier. The list manages selection using item identifiers:
struct Item: Identifiable, Transferable {
let color: Color
let name: String
let id = UUID()
static var transferRepresentation: some TransferRepresentation {
ProxyRepresentation(exporting: \.name)
}
}
struct CopyableIDExample: View {
let items: [Item] = [
Item(color: .red, name: "red"),
Item(color: .green, name: "green"),
Item(color: .blue, name: "blue")
]
@State private var selection: Set<Item.ID> = []
var body: some View {
List(items, selection: $selection) { item in
item.color
}
.copyable(items.filter { selection.contains($0.id) })
}
}
This example does two things that the previous example didn't have to:
- It converts the list of selected item identifiers into a list of
selected items for use with the copyable modifier.
- It ensures that the copyable items conform to the
<doc://com.apple.documentation/documentation/coretransferable/transferable> protocol, using the item's name property as the representation.
When someone copies the first item in the list, which appears in the interface as a red rectangle, and then pastes into a text editor, they get the string "red".
Note: To enable people to copy using a custom action --- like from a
context menu item --- rather than using the system Copy command, update the Clipboard directly using an <doc://com.apple.documentation/documentation/appkit/nspasteboard> or a <doc://com.apple.documentation/documentation/uikit/uipasteboard> instance.
Parameters
payload- A closure that returns an array of items to copy to the Clipboard when someone issues a Copy command. The items in the array must conform to the <doc://com.apple.documentation/documentation/coretransferable/transferable> protocol.
ReturnsA view that adds one or more items to the Clipboard in response to a Copy command.
func
View.cuttable
NewiOSnonisolated public func cuttable<T>(for payloadType: T.Type = T.self, action: @escaping () -> [T]) -> some View where T : Transferable
Specifies an action that moves items to the Clipboard in response to the system's Cut command.
Use this modifier to remove one or more items from a collection of items and then move the items to the Clipboard when someone issues a Cut command. People issue a Cut command by choosing Edit > Cut from the app's menu, or by using the Command-X keyboard shortcut. The system enables the Cut command for your app when it detects cuttable content.
For example, the following code enables people to remove bird names from a list of birds:
struct CuttableExample: View {
@State private var birds = ["owl", "parrot", "swift"]
@State private var selection: Set<String> = []
var body: some View {
List(birds, id: \.self, selection: $selection) {
Text($0)
}
.cuttable(for: String.self) {
for bird in selection {
birds.removeAll(where: { $0 == bird })
}
return Array(selection)
}
}
}
When someone selects "owl" and issues a Cut command, the action closure removes the selected item from the list and returns it. In response, SwiftUI moves it to the Clipboard. If you want to copy the item without removing it, use the copyable(_:) modifier instead.
Note: To enable people to cut using a custom action --- like from a
context menu item --- rather than using the system Cut command, update the Clipboard directly using an <doc://com.apple.documentation/documentation/appkit/nspasteboard> or a <doc://com.apple.documentation/documentation/uikit/uipasteboard> instance.
Parameters
payloadType- The type of items to cut.
action- A closure that you implement to delete the selected items from the collection, and return them for addition to the Clipboard. The items must conform to the <doc://com.apple.documentation/documentation/coretransferable/transferable> protocol.
ReturnsA view that sends one or more items to the Clipboard in response to a Cut command.
func
View.onDragSessionUpdated
NewiOSnonisolated public func onDragSessionUpdated(_ onUpdate: @escaping (DragSession) -> Void) -> some View
Specifies an action to perform on each update of an ongoing dragging operation activated by draggable(_:) or anther drag modifiers.
Below is an example of a view that displays a book and supports dragging to copy, move, and delete. If the session ends with moving or deleting the item, in the onUpdate closure, the view lets the model layer know that the book should be deleted from the source.
struct DraggableBookView: View {
var id: UUID
var body: some View {
BookView()
.draggable(
configuration: DragConfiguration(
operationsWithinApp: .init(allowMove: true, allowDelete: true),
operationsOutsideApp: .init(allowMove: true, allowDelete: true)
), Book(id: id))
.onDragSessionUpdated { session in
switch session.phase {
case .ended(at: _, with: let operation):
if operation == .move || operation == .delete {
if let id = session.draggedItemIDs(type: UUID.self).first {
removeBook(id: id)
}
}
default:
break
}
}
}
}
func removeBook(id: UUID) { }
The onUpdate closure is called when the closest drag session in the child view hierarchy becomes active.
func
View.pasteDestination
NewiOSnonisolated public func pasteDestination<T>(for payloadType: T.Type = T.self, action: @escaping ([T]) -> Void, validator: @escaping ([T]) -> [T] = { $0 }) -> some View where T : Transferable
Specifies an action that adds validated items to a view in response to the system's Paste command.
Use this modifier to paste one or more items into a view from the Clipboard when someone issues a Paste command. People issue a Paste command by choosing Edit > Paste from the app's menu, or by using the Command-V keyboard shortcut. The system enables the Paste command for your app when the view in focus provides a paste destination.
For example, the following code enables people to paste bird names into a list:
struct PasteDestinationExample: View {
@State private var birds: [String] = []
@State private var selection: Set<String> = []
let knownBirds = ["owl", "parrot", "swift",
"sparrow", "robin", "bluebird"]
var body: some View {
List(birds, id: \.self, selection: $selection) {
Text($0)
}
.pasteDestination(for: String.self) { values in
birds.append(contentsOf: values)
} validator: { values in
values.filter { knownBirds.contains($0) }
}
}
}
The paste destination handles only pasted content with a type that matches the payloadType that you specify. The list in the above example only accepts strings.
Use the validator closure to restrict the pasted content to items that make sense in the context of the view. The above example allows people to paste only strings that match one of a known list of bird names because the list is meant to contain only birds. You can omit the final closure if you don't need to perform any validation.
Note: To enable people to paste using a custom action --- like from a
context menu item --- rather than using the system Paste command, access the Clipboard directly using an <doc://com.apple.documentation/documentation/appkit/nspasteboard> or a <doc://com.apple.documentation/documentation/uikit/uipasteboard> instance.
Parameters
payloadType- The type of data that the paste destination accepts. The type must conform to the <doc://com.apple.documentation/documentation/coretransferable/transferable> protocol.
action- The action to perform when someone uses the system's Paste command to paste one or more items of the payload type. The closure takes one parameter, which is the array of items to paste.
validator- A closure that you implement to validate the data to paste. SwiftUI calls this before it calls the
action closure, and passes in an array of items to validate. Inspect the items, and return an array that includes only those from the input array that you consider valid. The array that you return from this closure becomes the input to the action closure. If you return an empty array, SwiftUI doesn't call the action closure.
ReturnsA view that people can paste into using the system Paste command.
func
View.reorderContainer
NewiOSmacOSwatchOSnonisolated public func reorderContainer<Item>(for item: Item.Type, isEnabled: Bool = true, move: @escaping (_ difference: ReorderDifference<Item.ID, ReorderableSingleCollectionIdentifier>) -> ()) -> some View where Item : Identifiable, Item.ID : Sendable
Defines a container that allows its items to be reordered.
Declare this modifier on your container or layout view to make it a reorderable container. Then, apply reorderable(collectionID:) to the content of your container to make those items reorderable.
Use this overload if your container only has one collection within it. If you have multiple collections of reorderable items, use reorderContainer(for:in:isEnabled:move:) and provide a type for collection identifiers.
A reorderable item within the container can be lifted using a drag gesture. As that item lifts, a placeholder view will take its place to indicate where the moved view will be when dropped. As your user moves the item through the container, the position of the placeholder will update to be the last item that your user dragged over. When they drop the item, the move closure will be called with the change provided.
The change is provided as a difference to the closure. The difference contains the identifiers of the moved items, in the order that the user selected them. It also contains a destination value, which indicates where to insert the item.
If your single collection conforms to MutableCollection, you can use the difference's apply(to:) method to apply the change directly to your closure.
This example shows a list of landmarks. Items can be moved within the view's underlying collection.
struct ContentView: View {
@State private var landmarks: [Landmark] = []
var body: some View {
VStack {
ForEach(landmarks) { landmark in
LandmarkView(landmark)
}
.reorderable()
}
.reorderContainer(for: Landmark.self) { difference in
difference.apply(to: &landmarks)
}
}
}
Parameters
item- The type of reorderable items in the container.
isEnabled- Whether the container allows reordering.
move- A closure that provides the change at the end of a session.
func
View.reorderContainer
NewiOSmacOSwatchOSnonisolated public func reorderContainer<Item, CollectionID>(for item: Item.Type, in collectionID: CollectionID.Type, isEnabled: Bool = true, move: @escaping (_ difference: ReorderDifference<Item.ID, CollectionID>) -> ()) -> some View where Item : Identifiable, CollectionID : Hashable, CollectionID : Sendable, Item.ID : Sendable
Defines a container that allows its items to be reordered.
Declare this modifier on your container or layout view to make it a reorderable container. Then, apply reorderable() to the content of your container to make those items reorderable.
Use this overload if your container has multiple collections in it. If your container only has a single collection, use the convenience reorderContainer(for:isEnabled:move:) modifier.
A reorderable item within the container can be lifted using a drag gesture. As that item lifts, a placeholder view will take its place to indicate where the moved view will be when dropped. As your user moves the item through the container, the position of the placeholder will update to be the last item that your user dragged over. When they drop the item, the move closure will be called with the change provided.
The change is provided as a difference to the closure. The difference contains the identifiers of the moved items, in the order that the user selected them. It also contains a destination value, which indicates where to insert the item.
This example shows a list of reminders. Items can be moved within the list's underlying collections.
struct ContentView: View {
@State private var model = ReminderModel()
var body: some View {
List {
ForEach(model.sections) { section in
Section(section.name) {
ForEach(section.reminders) { reminder in
ReminderView(reminder)
}
.reorderable(collectionID: section.id)
}
}
}
.reorderContainer(
for: Reminder.self, in: ReminderModel.Section.ID.self
) { difference in
model.apply(difference: difference)
}
}
}
Parameters
item- The type of reorderable items in the container.
collectionID- The type used to identify collections of reorderable items in the container.
isEnabled- Whether the container allows reordering.
move- A closure that provides the change at the end of a session.
func
View.reorderContainer
NewiOSmacOSwatchOSnonisolated public func reorderContainer<Item, ItemID>(for item: Item.Type, itemID: KeyPath<Item, ItemID>, isEnabled: Bool = true, move: @escaping (_ difference: ReorderDifference<ItemID, ReorderableSingleCollectionIdentifier>) -> ()) -> some View where ItemID : Hashable, ItemID : Sendable
Defines a container that allows its items to be reordered.
Declare this modifier on your container or layout view to make it a reorderable container. Then, apply reorderable(collectionID:) to the content of your container to make those items reorderable.
Use this overload if your container only has one collection within it. If you have multiple collections of reorderable items, use reorderContainer(for:in:isEnabled:move:) and provide a type for collection identifiers.
A reorderable item within the container can be lifted using a drag gesture. As that item lifts, a placeholder view will take its place to indicate where the moved view will be when dropped. As your user moves the item through the container, the position of the placeholder will update to be the last item that your user dragged over. When they drop the item, the move closure will be called with the change provided.
The change is provided as a difference to the closure. The difference contains the identifiers of the moved items, in the order that the user selected them. It also contains a destination value, which indicates where to insert the item.
If your single collection conforms to MutableCollection, you can use the difference's apply(to:) method to apply the change directly to your closure.
This example shows a stack of landmarks. Items can be moved within the view's underlying collection.
struct ContentView: View {
@State private var landmarks: [Landmark] = []
@State private var selection = Set<Landmark.ID>()
var body: some View {
List(selection: $selection) {
ForEach(landmarks, id: \.location) { landmark in
LandmarkView(landmark)
}
.reorderable()
}
.reorderContainer(for: Landmark.self, id: \.location) {
(difference) in
difference.apply(to: &landmarks)
}
}
}
Parameters
item- The type of reorderable items in the container.
itemID- A keypath to the identifier used to represent this item.
isEnabled- Whether the container allows reordering.
move- A closure that provides the change at the end of a session.
func
View.reorderContainer
NewiOSmacOSwatchOSnonisolated public func reorderContainer<Item, ItemID, CollectionID>(for item: Item.Type, itemID: KeyPath<Item, ItemID>, in collectionID: CollectionID.Type, isEnabled: Bool = true, move: @escaping (_ difference: ReorderDifference<ItemID, CollectionID>) -> ()) -> some View where ItemID : Hashable, ItemID : Sendable, CollectionID : Hashable, CollectionID : Sendable
Defines a container that allows its items to be reordered.
Declare this modifier on your container or layout view to make it a reorderable container. Then, apply reorderable() to the content of your container to make those items reorderable.
Use this overload if your container has multiple collections in it. If your container only has a single collection, use the convenience reorderContainer(for:isEnabled:move:) modifier.
A reorderable item within the container can be lifted using a drag gesture. As that item lifts, a placeholder view will take its place to indicate where the moved view will be when dropped. As your user moves the item through the container, the position of the placeholder will update to be the last item that your user dragged over. When they drop the item, the move closure will be called with the change provided.
The change is provided as a difference to the closure. The difference contains the identifiers of the moved items, in the order that the user selected them. It also contains a destination value, which indicates where to insert the item.
This example shows a list of reminders. Items can be moved within the list's underlying collections.
struct ContentView: View {
@State private var model = ReminderModel()
var body: some View {
List {
ForEach(model.sections) { section in
Section(section.name) {
ForEach(
section.reminders, id: \.databaseID
) { reminder in
ReminderView(reminder)
}
.reorderable(collectionID: section.id)
}
}
}
.reorderContainer(
for: Reminder.self, itemID: \.databaseID,
in: ReminderModel.Section.ID.self
) { difference in
model.apply(difference: difference)
}
}
}
Parameters
item- The type of reorderable items in the container.
itemID- A keypath to the identifier used to represent this item.
collectionID- The type used to identify collections of reorderable items in the container.
isEnabled- Whether the container allows reordering.
move- A closure that provides the change at the end of a session.
No APIs match your filter.