List
public struct List<Selection, Content> where Selection : SelectionManager, Content : View {
/// Creates an instance.
///
/// - Parameter selection: A selection manager that identifies the selected row(s).
///
/// - See Also: `View.selectionValue` which gives an identifier to the rows.
///
/// - Note: On iOS and tvOS, you must explicitly put the `List` into Edit
/// Mode for the selection to apply.
@available(watchOS, unavailable)
public init(selection: Binding<Selection>?, content: () -> Content)
/// 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` property.
public typealias Body = Never
}
实例:
List(landmarkData) { landmark in
NavigationButton(destination: LandmarkDetail(landmark: landmark)) {
LandmarkRow(landmark: landmark)
}
}
Nav
public struct NavigationView<Root> where Root : View {
public init(root: () -> Root)
public var body: _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 `body` property.
public typealias Body
}
实例
NavigationView {
Text("我是内容").navigationBarTitle(Text("我是标题"), displayMode: .large)
}
ForEach
public struct ForEach<Data, Content> where Data : RandomAccessCollection, Content : View, Data.Element : Identifiable {
/// The collection of underlying identified data.
public var data: Data
/// A function that can be used to generate content on demand given
/// underlying data.
public var content: (Data.Element.IdentifiedValue) -> Content
/// Creates an instance that uniquely identifies views across updates based
/// on the identity of the underlying data element.
///
/// It's important that the id of a data element does not change
/// unless the data element is considered to have been replaced with a new
/// data element with a new identity. If the id of a data element
/// changes, then the content view generated from that data element will
/// lose any current state and animations.
public init(_ data: Data, content: @escaping (Data.Element.IdentifiedValue) -> Content)
/// 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` property.
public typealias Body = Never
}
实例:多屏时时预览
#if DEBUG
struct LandmarkList_Previews: PreviewProvider {
static var previews: some View {
ForEach(["iPhone SE", "iPhone XS Max"].identified(by: .self)) { deviceName in
LandmarkList()
.previewDevice(PreviewDevice(rawValue: deviceName))
.previewDisplayName(deviceName)
}
}
}
#endif
Group
public struct Group<Content> where Content : View {
public init(content: () -> Content)
/// 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` property.
public typealias Body = Never
}
实例:
#if DEBUG
struct LandmarkRow_Previews: PreviewProvider {
static var previews: some View {
Group {
LandmarkRow(landmark: landmarkData[0])
LandmarkRow(landmark: landmarkData[1])
}
.previewLayout(.fixed(width: 300, height: 70))
}
}
#endif
实例数据根据官方实例修改说明