{"abstract":[{"text":"A type-erased instance of the layout protocol.","type":"text"}],"hierarchy":{"paths":[["doc:\/\/com.apple.documentation\/documentation\/technologies","doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI"]]},"identifier":{"interfaceLanguage":"swift","url":"doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/AnyLayout"},"kind":"symbol","legalNotices":{"copyright":"Copyright &copy; 2026 Apple Inc. All rights reserved.","privacyPolicy":"https:\/\/www.apple.com\/privacy\/privacy-policy","termsOfUse":"https:\/\/www.apple.com\/legal\/internet-services\/terms\/site.html"},"metadata":{"availableLanguages":["de-DE","en-US","es-419","fr-FR","it-IT","ja-JP","ko-KR","pt-BR","zh-CN"],"externalID":"s:7SwiftUI9AnyLayoutV","fragments":[{"kind":"keyword","text":"struct"},{"kind":"text","text":" "},{"kind":"identifier","text":"AnyLayout"}],"modules":[{"name":"SwiftUI"}],"navigatorTitle":[{"kind":"identifier","text":"AnyLayout"}],"platforms":[{"introducedAt":"16.0","name":"iOS"},{"introducedAt":"16.0","name":"iPadOS"},{"introducedAt":"16.0","name":"Mac Catalyst"},{"introducedAt":"13.0","name":"macOS"},{"introducedAt":"16.0","name":"tvOS"},{"introducedAt":"1.0","name":"visionOS"},{"introducedAt":"9.0","name":"watchOS"}],"role":"symbol","roleHeading":"Structure","symbolKind":"struct","title":"AnyLayout"},"primaryContentSections":[{"declarations":[{"languages":["swift"],"platforms":["iOS","iPadOS","Mac Catalyst","macOS","tvOS","visionOS","watchOS"],"tokens":[{"kind":"attribute","text":"@frozen"},{"kind":"text","text":" "},{"kind":"keyword","text":"struct"},{"kind":"text","text":" "},{"kind":"identifier","text":"AnyLayout"}]}],"kind":"declarations"},{"content":[{"anchor":"overview","level":2,"text":"Overview","type":"heading"},{"inlineContent":[{"text":"Use an ","type":"text"},{"code":"AnyLayout","type":"codeVoice"},{"text":" instance to enable dynamically changing the","type":"text"},{"text":" ","type":"text"},{"text":"type of a layout container without destroying the state of the subviews.","type":"text"},{"text":" ","type":"text"},{"text":"For example, you can create a layout that changes between horizontal and","type":"text"},{"text":" ","type":"text"},{"text":"vertical layouts based on the current Dynamic Type setting:","type":"text"}],"type":"paragraph"},{"code":["struct DynamicLayoutExample: View {","    @Environment(\\.dynamicTypeSize) var dynamicTypeSize","","    var body: some View {","        let layout = dynamicTypeSize <= .medium ?","            AnyLayout(HStackLayout()) : AnyLayout(VStackLayout())","","        layout {","            Text(\"First label\")","            Text(\"Second label\")","        }","    }","}"],"copyToClipboard":true,"lineAnnotations":[],"showLineNumbers":false,"syntax":"swift","type":"codeListing","wrap":0},{"inlineContent":[{"text":"The types that you use with ","type":"text"},{"code":"AnyLayout","type":"codeVoice"},{"text":" must conform to the ","type":"text"},{"identifier":"doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/Layout","isActive":true,"type":"reference"},{"text":" ","type":"text"},{"text":"protocol. The above example chooses between the ","type":"text"},{"identifier":"doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/HStackLayout","isActive":true,"type":"reference"},{"text":" and","type":"text"},{"text":" ","type":"text"},{"identifier":"doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/VStackLayout","isActive":true,"type":"reference"},{"text":" types, which are versions of the built-in ","type":"text"},{"identifier":"doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/HStack","isActive":true,"type":"reference"},{"text":" ","type":"text"},{"text":"and ","type":"text"},{"identifier":"doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/VStack","isActive":true,"type":"reference"},{"text":" containers that conform to the protocol. You can also","type":"text"},{"text":" ","type":"text"},{"text":"use custom layout types that you define.","type":"text"}],"type":"paragraph"}],"kind":"content"}],"relationshipsSections":[{"identifiers":["doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/Animatable","doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/Layout","doc:\/\/com.apple.documentation\/documentation\/Swift\/Sendable","doc:\/\/com.apple.documentation\/documentation\/Swift\/SendableMetatype"],"kind":"relationships","title":"Conforms To","type":"conformsTo"}],"schemaVersion":{"major":0,"minor":3,"patch":0},"sections":[],"seeAlsoSections":[{"anchor":"Transitioning-between-layout-types","generated":true,"identifiers":["doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/HStackLayout","doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/VStackLayout","doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/ZStackLayout","doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/GridLayout"],"title":"Transitioning between layout types"}],"topicSections":[{"anchor":"Creating-the-layout","identifiers":["doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/AnyLayout\/init(_:)"],"title":"Creating the layout"}],"variants":[{"paths":["\/documentation\/swiftui\/anylayout"],"traits":[{"interfaceLanguage":"swift"}]}],"references":{"SwiftUI-PageImage-card.png":{"alt":"A stylized Swift logo using dashes on a white or blue background.","identifier":"SwiftUI-PageImage-card.png","type":"image","variants":[{"traits":["2x","light"],"url":"\/images\/com.apple.SwiftUI\/SwiftUI-PageImage-card@2x.png"},{"traits":["2x","dark"],"url":"\/images\/com.apple.SwiftUI\/SwiftUI-PageImage-card~dark@2x.png"}]},"doc://com.apple.SwiftUI/documentation/SwiftUI":{"abstract":[{"text":"Declare the user interface and behavior for your app on every platform.","type":"text"}],"identifier":"doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI","images":[{"identifier":"SwiftUI-PageImage-card.png","type":"card"}],"kind":"symbol","role":"collection","title":"SwiftUI","type":"topic","url":"\/documentation\/swiftui"},"doc://com.apple.SwiftUI/documentation/SwiftUI/Animatable":{"abstract":[{"text":"A type that describes how to animate a property of a view.","type":"text"}],"fragments":[{"kind":"keyword","text":"protocol"},{"kind":"text","text":" "},{"kind":"identifier","text":"Animatable"}],"identifier":"doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/Animatable","kind":"symbol","navigatorTitle":[{"kind":"identifier","text":"Animatable"}],"role":"symbol","title":"Animatable","type":"topic","url":"\/documentation\/swiftui\/animatable"},"doc://com.apple.SwiftUI/documentation/SwiftUI/AnyLayout":{"abstract":[{"text":"A type-erased instance of the layout protocol.","type":"text"}],"fragments":[{"kind":"keyword","text":"struct"},{"kind":"text","text":" "},{"kind":"identifier","text":"AnyLayout"}],"identifier":"doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/AnyLayout","kind":"symbol","navigatorTitle":[{"kind":"identifier","text":"AnyLayout"}],"role":"symbol","title":"AnyLayout","type":"topic","url":"\/documentation\/swiftui\/anylayout"},"doc://com.apple.SwiftUI/documentation/SwiftUI/AnyLayout/init(_:)":{"abstract":[{"text":"Creates a type-erased value that wraps the specified layout.","type":"text"}],"fragments":[{"kind":"identifier","text":"init"},{"kind":"text","text":"<"},{"kind":"genericParameter","text":"L"},{"kind":"text","text":">("},{"kind":"typeIdentifier","text":"L"},{"kind":"text","text":")"}],"identifier":"doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/AnyLayout\/init(_:)","kind":"symbol","role":"symbol","title":"init(_:)","type":"topic","url":"\/documentation\/swiftui\/anylayout\/init(_:)"},"doc://com.apple.SwiftUI/documentation/SwiftUI/GridLayout":{"abstract":[{"text":"A grid that you can use in conditional layouts.","type":"text"}],"fragments":[{"kind":"keyword","text":"struct"},{"kind":"text","text":" "},{"kind":"identifier","text":"GridLayout"}],"identifier":"doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/GridLayout","kind":"symbol","navigatorTitle":[{"kind":"identifier","text":"GridLayout"}],"role":"symbol","title":"GridLayout","type":"topic","url":"\/documentation\/swiftui\/gridlayout"},"doc://com.apple.SwiftUI/documentation/SwiftUI/HStack":{"abstract":[{"text":"A view that arranges its subviews in a horizontal line.","type":"text"}],"fragments":[{"kind":"keyword","text":"struct"},{"kind":"text","text":" "},{"kind":"identifier","text":"HStack"}],"identifier":"doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/HStack","kind":"symbol","navigatorTitle":[{"kind":"identifier","text":"HStack"}],"role":"symbol","title":"HStack","type":"topic","url":"\/documentation\/swiftui\/hstack"},"doc://com.apple.SwiftUI/documentation/SwiftUI/HStackLayout":{"abstract":[{"text":"A horizontal container that you can use in conditional layouts.","type":"text"}],"fragments":[{"kind":"keyword","text":"struct"},{"kind":"text","text":" "},{"kind":"identifier","text":"HStackLayout"}],"identifier":"doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/HStackLayout","kind":"symbol","navigatorTitle":[{"kind":"identifier","text":"HStackLayout"}],"role":"symbol","title":"HStackLayout","type":"topic","url":"\/documentation\/swiftui\/hstacklayout"},"doc://com.apple.SwiftUI/documentation/SwiftUI/Layout":{"abstract":[{"text":"A type that defines the geometry of a collection of views.","type":"text"}],"fragments":[{"kind":"keyword","text":"protocol"},{"kind":"text","text":" "},{"kind":"identifier","text":"Layout"}],"identifier":"doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/Layout","kind":"symbol","navigatorTitle":[{"kind":"identifier","text":"Layout"}],"role":"symbol","title":"Layout","type":"topic","url":"\/documentation\/swiftui\/layout"},"doc://com.apple.SwiftUI/documentation/SwiftUI/VStack":{"abstract":[{"text":"A view that arranges its subviews in a vertical line.","type":"text"}],"fragments":[{"kind":"keyword","text":"struct"},{"kind":"text","text":" "},{"kind":"identifier","text":"VStack"}],"identifier":"doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/VStack","kind":"symbol","navigatorTitle":[{"kind":"identifier","text":"VStack"}],"role":"symbol","title":"VStack","type":"topic","url":"\/documentation\/swiftui\/vstack"},"doc://com.apple.SwiftUI/documentation/SwiftUI/VStackLayout":{"abstract":[{"text":"A vertical container that you can use in conditional layouts.","type":"text"}],"fragments":[{"kind":"keyword","text":"struct"},{"kind":"text","text":" "},{"kind":"identifier","text":"VStackLayout"}],"identifier":"doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/VStackLayout","kind":"symbol","navigatorTitle":[{"kind":"identifier","text":"VStackLayout"}],"role":"symbol","title":"VStackLayout","type":"topic","url":"\/documentation\/swiftui\/vstacklayout"},"doc://com.apple.SwiftUI/documentation/SwiftUI/ZStackLayout":{"abstract":[{"text":"An overlaying container that you can use in conditional layouts.","type":"text"}],"fragments":[{"kind":"keyword","text":"struct"},{"kind":"text","text":" "},{"kind":"identifier","text":"ZStackLayout"}],"identifier":"doc:\/\/com.apple.SwiftUI\/documentation\/SwiftUI\/ZStackLayout","kind":"symbol","navigatorTitle":[{"kind":"identifier","text":"ZStackLayout"}],"role":"symbol","title":"ZStackLayout","type":"topic","url":"\/documentation\/swiftui\/zstacklayout"},"doc://com.apple.documentation/documentation/Swift/Sendable":{"abstract":[{"text":"A thread-safe type whose values can be shared across arbitrary concurrent","type":"text"},{"text":" ","type":"text"},{"text":"contexts without introducing a risk of data races.","type":"text"}],"fragments":[{"kind":"keyword","text":"protocol"},{"kind":"text","text":" "},{"kind":"identifier","text":"Sendable"}],"identifier":"doc:\/\/com.apple.documentation\/documentation\/Swift\/Sendable","kind":"symbol","navigatorTitle":[{"kind":"identifier","text":"Sendable"}],"role":"symbol","title":"Sendable","type":"topic","url":"\/documentation\/swift\/sendable"},"doc://com.apple.documentation/documentation/Swift/SendableMetatype":{"abstract":[{"text":"A type whose metatype can be shared across arbitrary isolation domains","type":"text"},{"text":" ","type":"text"},{"text":"without introducing a risk of data races.","type":"text"}],"fragments":[{"kind":"keyword","text":"protocol"},{"kind":"text","text":" "},{"kind":"identifier","text":"SendableMetatype"}],"identifier":"doc:\/\/com.apple.documentation\/documentation\/Swift\/SendableMetatype","kind":"symbol","navigatorTitle":[{"kind":"identifier","text":"SendableMetatype"}],"role":"symbol","title":"SendableMetatype","type":"topic","url":"\/documentation\/swift\/sendablemetatype"},"doc://com.apple.documentation/documentation/technologies":{"abstract":[],"identifier":"doc:\/\/com.apple.documentation\/documentation\/technologies","kind":"technologies","role":"overview","title":"Technologies","type":"topic","url":"\/documentation\/technologies"}}}