Apple Developer Documentation

Hello world

List {           
}

SwiftUI에서 UIKit의 테이블 뷰 역할을 해주는 친구

ForEach

Apple Developer Documentation

//식별자 키경로
ForEach(scrums, id: \\.title) { scrum in
                
}
// identifiable 프로토콜 채택시 id를 생략해서 simple하게 코드작성가능

Identifiable

A class of types whose instances hold the value of an entity with stable identity.

객체의 식별자로 사용할 수 있도록 하는 프로토콜. 고유의 id를 부여한다.

import SwiftUI

struct DailyScrum: Identifiable {
    let id: UUID
    var title: String
    var attendees: [String]
    var lengthInMinutes: Int
    var color: Color
    
    init(id: UUID = UUID(), title: String, attendees: [String], lengthInMinutes: Int, color: Color) {
        self.id = id
        self.title = title
        self.attendees = attendees
        self.lengthInMinutes = lengthInMinutes
        self.color = color
    }
}

extension DailyScrum {
    static var data: [DailyScrum] {
        [
            DailyScrum(title: "Design", attendees: ["Cathy", "Daisy", "Simon", "Jonathan"], lengthInMinutes: 10, color: Color("Design")),
            DailyScrum(title: "App Dev", attendees: ["Katie", "Gray", "Euna", "Luis", "Darla"], lengthInMinutes: 5, color: Color("App Dev")),
            DailyScrum(title: "Web Dev", attendees: ["Chella", "Chris", "Christina", "Eden", "Karla", "Lindsey", "Aga", "Chad", "Jenn", "Sarah"], lengthInMinutes: 1, color: Color("Web Dev"))
        ]
    }
}

init 에서 UUID() 를 활용해서 기존의 초기화는 건들이지 않고 고유값을 추가함.

<aside> 💡 UUID() 함수는 어떻게 중복값없이 id값을 리턴하려나?

</aside>

Section

Section(header: Text("hello")) {
    Text("text1")
    Text("text2")
}

Section {
    Text("text1")
    Text("text2")
    Text("text3")
    Text("text4")
} header: {
    Text("header")
} footer: {
    Text("footer")
}

위에는 ⚠️deprecated, 밑에는 새로운 것으로 대체

확실히 새로 나온 프레임워크라 문법이나 함수, 사용법에 변동이 많음

Lifestyle