10:SwiftUI-ForEach

发布时间 2023-03-27 20:17:29作者: 风zk

 

 

正文

 

//
//  ForEachPage.swift
//  SwiftUIDeom
//
//  Created by zhoukang03 on 2023/3/27.
//
//  10:ForEach
// 参考:https://www.nuomiphp.com/a/stackoverflow/zh/6381066f89f7d936ef67d568.html
import SwiftUI

struct ForEachPage: View {
    let data = (0..<10)
    var body: some View {
        // 数据不能够动态删除或者增加,如果不加id:\.self
        ForEach(data, id: \.self) { index in
            Text("hello: \(index)")
                .bold()
                .font(.system(size: 18))
        }
        .border(Color.gray.gradient, width: 2)
        .cornerRadius(10)
        .navigationTitle("ForEach")
    }
}


#if DEBUG
// 预览视图
struct ForEachPage_Previews: PreviewProvider {
    static var previews: some View {
        ForEachPage()
    }
}
#endif