ForEvery

@_documentation(visibility: public)
@_spi(Experimental)
public struct ForEvery<Data, ID> : MapContent where Data : RandomAccessCollection, ID : Hashable

A structure that creates map content from an underlying collection of identified data.

Use ForEvery to create MapContent such as annotations from the identified data.

private struct Place: Identifiable {
    let name: String
    let coordinate: CLLocationCoordinate
    var id: String { name }
}

private let places = [
    Place(name: "Castle", coordinate: CLLocationCoordinate2D(...)),
    Place(name: "Lake", coordinate: CLLocationCoordinate2D(...))
]

var body: some View {
    Map {
      ForEvery(places) { place in
        ViewAnnotation(place.coordinate) {
            Image(named: place.name)
        }
      }
    }
}

Note

ForEvery is similar to SwiftUI ForEach, but works with MapContent.
  • Creates instance that uses identifiable data.

    Declaration

    Swift

    @available(iOS 13.0, *)
    @_documentation(visibility: public)
    public init(_ data: Data, @MapContentBuilder content: @escaping (Data.Element) -> MapContent) where ID == Data.Element.ID, Data.Element : Identifiable
  • Creates instance that identified data by given key path.

    Declaration

    Swift

    @_documentation(visibility: public)
    public init(_ data: Data, id: KeyPath<Data.Element, ID>, @MapContentBuilder content: @escaping (Data.Element) -> MapContent)