2022/11/09 (2) 썸네일형 리스트형 28. ForEach & Grid ForEach Apple Developer Documentation developer.apple.com struct View_ForEach: View { var items = AppleProduct.sampleList var body: some View { VStack { ForEach(items, id: \.name) { item in Text(item.name) } } } } 중간중간 등장했던 ForEach는 List나 이후에 살펴볼 Grid에서 폭넓게 사용된다. List와 마찬가지로 데이터를 나열한다는 점에서든 동일하지만, Table에 표시하지 않고 데이터들을 '나열' 하기만 한다. ForEach를 표시하는 형식은 ForEach가 어느 View에 Embed 됐는지가 기준이 됨을 기억하자. List의.. 27. List #2 List #2 Selection Apple Developer Documentation developer.apple.com 일반 모드 struct SingleSelection: View { var items = AppleProduct.sampleList @State private var selected: AppleProduct? = nil var body: some View { VStack { Text("Selected item: \(selected?.name ?? "_")") List(items) { item in Button { selected = item } label: { Text(item.name) } } } } } 일반적인 List에 Selection 기능을 구현한 경우이다. 특별한 생성자의 사.. 이전 1 다음