🕌

CodeWithChris Day 7: SwiftUI Buttons and Propertiesの記憶

2024/06/07に公開

CodeWithChrisでSwiftを学んでいる

学んだことの記録を残していきます。

CodeWithChris - The Leader in iOS Foundations Training : CodeWithChris https://codewithchris.com/

Buttonの使い型

基本形

Button("Deal") {
    print("Deal cards")
}
.foregroundColor(.white)

ボタンをイメージに置き換える

Button {
    deal()
} label: {
    Image("button")
}

funcとvarを記述する位置

Viewの中ではなく、外に記述する。


varはここに書く

var body: some View {
    Viewのコード
}

funcはここに書く

ハードコードを関数と変数に変換

var playerCard = "card7"
var cpuCard = "card13"
    
var playerScore = 0
var cpuScore = 10

var body: some View {
    Viewのコード
}

func deal() {
    print("Deal cards")
}

Discussion