Replies: 4 comments 3 replies
-
๋ฃจ๋ฏธ ๋ํ๋จผํธ ์ฐ์๋๋ผ ์ ๋ง ๊ณ ์๋ง์์ด์. ํญ์ ๊ถ๊ธํ๋๊ฑด๋ฐ ๊ณ ๋ง์์ฉ ! ๐ซก |
Beta Was this translation helpful? Give feedback.
0 replies
-
๋ฃจ๋ฏธ ์ต๊ณ ! ๊ฐ์ฌํฉ๋๋ค |
Beta Was this translation helpful? Give feedback.
0 replies
-
๊ฐ์ฌํฉ๋๋ค๐ |
Beta Was this translation helpful? Give feedback.
2 replies
-
์ข์ ๊ธ ๊ฐ์ฌํฉ๋๋ค! ์ด๋ฐ ์คํ์ ํด๋ณด์์ด์~ import SwiftUI
struct ContentView: View {
@State var count = 0 {
didSet {
print("b. count did set: \(count)")
}
}
init() {
print("a. CounterView init")
}
var body: some View {
print("c. body computed. \(count)\n")
return VStack {
Text("\(count)")
.font(.largeTitle)
HStack {
Button {
count -= 1
} label: {
Image(systemName: "minus")
}
Button {
count += 1
} label: {
Image(systemName: "plus")
}
}
}
.padding()
}
}
#Preview {
ContentView()
} 2025-04-26.10.42.18.mov์ค๋ช ๋๋ก ๋์ํ๋ ๊ฑธ ๋ณผ ์ ์์์ต๋๋ค!! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Overview
โก๏ธ ๊ณต์๋ฌธ์ ๋งํฌ
๐ง SwiftUI์ '@State' ๋?
SwiftUI์์
@State
๋ ๋ทฐ ๋ด๋ถ์ ๋ฐ์ดํฐ ์ํ๋ฅผ ์ ์ฅํ๊ณ ๊ด๋ฆฌํ๋ ์์ฑ ๋ํผ(Property Wrapper) ์ ๋๋ค.๊ฐ๋จํ ๋งํด, ํ๋ฉด์ ํ์๋๋ ๊ฐ์ด ๋ฐ๋ ๋ ์๋์ผ๋ก ํ๋ฉด(UI)์ ์ ๋ฐ์ดํธํด์ฃผ๋ ์ญํ ์ ํฉ๋๋ค.
โจ ์ธ์
@State
๋ฅผ ์ฌ์ฉํ ๊น?๐ ์์
1.
@State
๋ฅผ ์ผ์ ๋ โ โ๏ธ ์ ์๋ํจ2.
@State
๋ฅผ ์ ์ผ์ ๋ โ โ ์ปดํ์ผ ์๋ฌ"๋ค์ ๊ทธ๋ฆฐ๋ค."
'@State' ๋ฅผ ๋ถํ์ง ์๋๋ค๋ฉด?
"์ด๋ฏธ ๊ทธ๋ ค์ง ๊ทธ๋ฆผ์ ์์ ๋ฐ๊ฟ ์ ์์๊น์?"
์ฐ๋ฆฌ๋ ๊ทธ๋ฆผ์ ์์ ๋ฐ๊ฟ์ค -> ์์ ๋ฐ๊ฟ์ผ ํ๋๋ฐ,,, ๊ทธ๋ฅ ๋ค์ ๊ทธ๋ ค์ค ์ ์์๊น...?
'@State' ์ ์ญํ
์ด๋ ๊ฒ @State๋ฅผ ๋ถ์ด๋ฉด SwiftUI๋ ์ด๋ ๊ฒ ์๊ฐํฉ๋๋ค:
๊ทธ๋์ ๋ฒํผ์ ๋๋ฌ ์์ด ๋ฐ๋๋ฉด?
์ด๊ฒ ๋ฐ๋ก โ๋ค์ ๊ทธ๋ฆฐ๋คโ๋ ๊ฐ๋ ์ด์์.
๐ง๐ปโ๐ป ๊ฐ๋ฐ์์ ์ธ์ด ver. (๋ชฐ๋ผ๋ ๋จ)
โ๏ธ Summary
๐ ์ผ๋ฐ ๋ณ์ vs
@State
๋น๊ตBeta Was this translation helpful? Give feedback.
All reactions