iPhone SwiftUI layouts

Explore SwiftUI APIs, components, and modifiers with interactive iPhone previews, Swift code, and Apple documentation. Compare every available orientation, appearance, and design.

PhotosPicker

Container Photo Picker

Limits the Photos picker to only show items in the specified container. In this case, to the user-created album "CustomAlbum".

Explore Container Photo Picker on iPhone in portrait, with SwiftUI code and Apple API documentation.

@State private var selectedPhoto: PhotosPickerItem?
@State private var albumIdentifier: String?

var body: some View {
    PhotosPicker("FooBar", selection: $selectedPhoto)
        .photosPickerContainerIdentifier(albumIdentifier)
        .disabled(albumIdentifier == nil)
        .task { await loadAlbumIdentifier() }
}

private func loadAlbumIdentifier() async {
    guard await PHPhotoLibrary.requestAuthorization(for: .readWrite) == .authorized else {
        print("Full photo library access is required to find Custom Album.")
        return
    }

    let options = PHFetchOptions()
    options.predicate = NSPredicate(format: "title ==[c] %@", "CustomAlbum")

    guard let album = PHAssetCollection.fetchAssetCollections(
        with: .album,
        subtype: .albumRegular,
        options: options
    ).firstObject else {
        print("Custom Album not found.")
        return
    }

    albumIdentifier = album.localIdentifier
}
iOS 27.3+ iPadOS 27.3+ macOS 27.3+ visionOS 27.3+

Every available iPhone screenshot for Container Photo Picker.

1 views