appEntityIdentifier(forSelectionType:identifier:)
Associates the items in a SwiftUI list view with app entities to make them discoverable by Apple Intelligence and Siri.
Declaration
nonisolated func appEntityIdentifier<I>(forSelectionType itemType: I.Type = I.self, identifier: @escaping @Sendable (I) -> EntityIdentifier?) -> some View where I : Hashable
Discussion
Use this modifier to make app entities that describe data in a list discoverable by Apple Intelligence and Siri. This provides additional context to the system when the list appears onscreen and people scroll through it.
The following example associates a List view that displays books with an app entity for each book in the list.
struct BookListView: View {
let books: [Book]
@State private var selection = Set<Book.ID>()
var body: some View {
List(selection: $selection) {
ForEach(books) { book in
BookView(book.name)
}
}
.appEntityIdentifier(forSelectionType: Book.ID.self) { bookId in
EntityIdentifier(for: Book.self, identifier: bookId)
}
}
}For more information, refer to doc:Making-onscreen-content-available-to-siri-and-apple-intelligence and App Intents.