์ „์ฒด ๊ธ€

UIKit์œผ๋กœ ๊ฐœ๋ฐœํ•˜๋‹ค๊ฐ€ ํ˜„์žฌ๋Š” SwiftUI๋กœ ์„œ๋น„์Šค ๊ฐœ๋ฐœํ•˜๊ณ  ์žˆ๋Š” Fram์ž…๋‹ˆ๋‹ค SwiftUI์™€ Combine์— ๋Œ€ํ•ด ์•Œ๊ฒŒ ๋œ ๊ฒƒ๊ณผ ๊ธฐ์ˆ ์„ ๊ณต์œ ํ•˜๋Š” ๋ธ”๋กœ๊ทธ ์ž…๋‹ˆ๋‹ค. ์ฃผ์˜ : ์ ์—ˆ๋˜๊ฑฐ ๋˜ ์ ์„ ์ˆ˜ ์žˆ์Œ
TextField๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ String ํƒ€์ž…์„ Binding ํ•  ์ˆ˜ ์žˆ์Œ TextField("๊ฐ’์„ ์ž…๋ ฅํ•˜์„ธ์š”", text: ) String์ด ์•„๋‹Œ ํƒ€์ž…์„ Bindingํ•˜๋Š” ๊ฒฝ์šฐ ์—๋Ÿฌ ๋ฐœ์ƒํ•จ. ์ด๋•Œ format์„ ์‚ฌ์šฉํ•˜๋ฉด ํ”„๋กœํผํ‹ฐ์˜ ํƒ€์ž…์„ ๋ฐ”๊ฟ”์ฃผ์ง€ ์•Š๊ณ ๋„ ํ…์ŠคํŠธ ํ•„๋“œ์— ๊ฐ’์„ ํ‘œ์‹œํ•  ์ˆ˜ ์žˆ์Œ ใ„ด checkAmount ๊ฐ’์ด double์ด๊ธฐ ๋•Œ๋ฌธ์— TextField์˜ text ์ธ์ž์— Binding์œผ๋กœ ์ „๋‹ฌํ•˜๋Š” ๊ฒฝ์šฐ ์—๋Ÿฌ ๋ฐœ์ƒํ•จ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Œ TextField( "Proper name", value: $nameComponents, format: .name(style: .medium) ) ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ์œผ๋กœ ๋ถ€ํ„ฐ ์ „๋‹ฌ๋ฐ›์€ ๊ฐ’์„ ์ €์žฅํ•  ํ”„๋กœํผํ‹ฐ๋ฅผ value๋กœ ์ „๋‹ฌํ•˜๊ณ  format ํ˜•์‹์„ format ์ธ์ž๋กœ ์ „๋‹ฌ..
ForEach array, ranges์™€ ํ•จ๊ป˜ ๋ฐ˜๋ณต ์ž‘์—…์„ ํ†ตํ•ด ์—ฌ๋Ÿฌ ๋ทฐ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Œ ํด๋กœ์ ธ๋ฅผ ํ†ตํ•ด ์‹คํ–‰๋˜๋ฉฐ loop์˜ ๋ชจ๋“  ์•„์ดํ…œ์„ ํ•œ๋ฒˆ์”ฉ ์ˆœํ™˜ํ•˜๊ฒŒ ๋จ class test { init() { let titles = ["a", "b", "c", "d", "e"] self.loopAllItems(items: titles) } func loopAllItems(items: [String]) { items.forEach { print($0) } } } ForEach๋Š” ๊ธฐ์กด์— Swift์—์„œ ์‚ฌ์šฉํ•œ ๊ณ ์ฐจ ํ•จ์ˆ˜ forEach์™€ ๋™์ž‘๊ณผ ์‚ฌ์šฉ๋ฒ•์ด ๊ฐ™์Œ ScrollView { ForEach(0 ..< 100) { Text("\($0)") } } ForEach๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋ฐ˜๋ณต๋˜๋Š” ๋ทฐ๋ฅผ ๊ฐ„๋‹จํ•œ ์ฝ”๋“œ๋กœ ํ™”๋ฉด์— ๊ทธ๋ ค ์ค„ ์ˆ˜..
๋‹ฌ๋Ÿฌ์‚ฌ์ธ์€ two-way binding์„ ํ•  ๋•Œ ์‚ฌ์šฉ๋จ Text("๋‹น์‹ ์˜ ๋‚˜์ด๋Š” : \(age)") Text์˜ ๊ฒฝ์šฐ ํ”„๋กœํผํ‹ฐ์˜ ์ƒํƒœ๋ฅผ ๊ทธ๋Œ€๋กœ ๋ณด์—ฌ์คŒ TextField์˜ ๊ฒฝ์šฐ text๋ผ๋Š” ์ธ์ž์— ํ•„์š”ํ•œ ๊ฐ’์ด Binding two-way binding์€ ํ”„๋กœํผํ‹ฐ์˜ ์ƒํƒœ ๊ฐ’์„ ํ™”๋ฉด์— ๋ณด์—ฌ์ฃผ๋ฉด์„œ ํ•ด๋‹น ์ƒํƒœ๊ฐ’์„ ์—…๋ฐ์ดํŠธ ํ•˜๊ณ , ๊ทธ ์—…๋ฐ์ดํŠธ ํ•œ ๊ฐ’์„ ๋‹ค์‹œ ํ™”๋ฉด์— ๋ณด์—ฌ์ค„ ์ˆ˜ ์žˆ์Œ struct ContentView: View { @State private var age = "" var body: some View { VStack { TextField("๋‚˜์ด๋ฅผ ์ž…๋ ฅํ•˜์‹œ์˜ค.", text: $age) Text("๋‹น์‹ ์˜ ๋‚˜์ด๋Š” : \(age)") }.padding() } } two-way binding์€ ํ”„๋กœํผํ‹ฐ ๋ฐ”๋กœ ์•ž์— ..
์˜ˆ์‹œ ์ฝ”๋“œ struct ContentView: View { @State private var count = 0 @State private var isOne = false var body: some View { VStack { Button("๋ฒ„ํŠผ ๋ˆŒ๋ฆฐ ํšŸ์ˆ˜ \(count)") { self.count += 1 } Toggle(isOn: $isOne) { Text("ํ† ๊ธ€ ์ƒํƒœ \(isOne ? "on" : "off")") } } } } SwiftUI์—์„œ View ๋‹จ์œ„์˜ ๊ฐ„๋‹จํ•œ ๊ฐ’์„ State๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๊ด€๋ฆฌํ•˜๋Š”๋ฐ ์ด๋•Œ Button์€ State์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•ด self๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  Toggle์€ ๋‹ฌ๋Ÿฌ ์‚ฌ์ธ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ์•Œ์ˆ˜ ์žˆ๋‹ค. ์‚ฌ์‹ค ๊ฐ๊ฐ ํ”„๋กœํผํ‹ฐ์— ์ ‘๊ทผํ•  ๋•Œ ์—ญํ• ๊ณผ ์œ„์น˜๊ฐ€ ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. State์˜ ๊ฐ’..
Intro ํ˜„์žฌ ๋ทฐ์—์„œ ๋ณด์—ฌ์ง€๋Š” ๋ฐ์ดํ„ฐ๋“ค์„ State๋กœ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Œ. ์ด ์ƒํƒœ์— ์˜ํ•ด ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ง€๋Š” UI๋ฅผ ๊ด€๋ฆฌํ•˜๋ฏ€๋กœ views are a function of their state ๋ผ๊ณ  ํ•˜๊ธฐ๋„ ํ•จ (์‚ฌ์šฉ์ž์˜ ์ •๋ณด๋ฅผ ์ž…๋ ฅํ•˜๊ธฐ ์ „๊นŒ์ง€ ๋ฒ„ํŠผ์„ ๋น„ํ™œ์„ฑํ™” ์‹œํ‚ค๋Š” ๊ฒƒ๋„ state๋“ค์— ์˜ํ•ด ๋ทฐ๊ฐ€ ๊ด€๋ฆฌ๋˜๋Š” ๊ฒƒ) SwiftUI๋Š” struct๋กœ ๊ตฌํ˜„๋œ view๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— Swift์™€ UIKit์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ ์ฒ˜๋Ÿผ ๋‹จ์ˆœํžˆ property๋ฅผ ์„ ์–ธํ•œ ๋’ค ๊ตฌ์กฐ์ฒด ์•ˆ์—์„œ ๊ทธ ๊ฐ’์„ ๋ฐ”๊ฟ€์ˆ˜ ์—†์Œ ํ”„๋กœํผํ‹ฐ์˜ ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜๊ธฐ ์œ„ํ•ด์„œ State๋ผ๋Š” ํ‚ค์›Œ๋“œ๋ฅผ ๊ฐ€์ง„ property wrapper๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ SwiftUI๋Š” ๋ทฐ๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ๋‹ค์‹œ ๊ทธ๋ฆฌ๋Š” ์ผ์„ ์ž์ฃผ ๋ฐ˜๋ณตํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ทฐ ๋‚ด๋ถ€์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ’์— ๋Œ€ํ•ด ๋‹จ์ˆœํ•˜๊ฒŒ..
๊ธฐ์กด์— ์‚ฌ์šฉ๋˜๋˜ NavigaitonView๋Š” Deprecated ๋˜๊ณ  NavigationView์™€ ๋™์ผํ•˜๊ฒŒ NavigationStack์„ ์‚ฌ์šฉํ•˜๋ฉด ๋จ home indicator์™€ ์‹œ๊ณ„๋ฅผ ํฌํ•จํ•œ ์ƒ๋‹จ ์˜์—ญ์—๋„ ๋ทฐ๋ฅผ ์œ„์น˜ ์‹œํ‚ฌ ์ˆ˜ ์žˆ์œผ๋‚˜ ์ปจํ…์ธ ๊ฐ€ ๊ฒน์น˜๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉ์ž๊ฐ€ ๋ณด๊ธฐ์— ๋ถˆํŽธํ•  ์ˆ˜ ์žˆ์Œ SwiftUI๋Š” ์‹œ์Šคํ…œ UI๋‚˜ ๊ธฐ๊ธฐ์˜ ์ฝ”๋„ˆ ์˜์—ญ์„ ํ”ผํ•ด ์ปดํฌ๋„ŒํŠธ๋ฅผ ์œ„์น˜ ์‹œํ‚ฌ ์ˆ˜ ์žˆ์œผ๋‚˜ ์Šคํฌ๋กค ์‹œ ์‹œ์Šคํ…œ ์˜์—ญ์— ๊ฒน์น  ์ˆ˜ ์žˆ์Œ ๋„ค๋น„๊ฒŒ์ด์…˜์„ ์‚ฌ์šฉํ•˜๋ฉด ์ƒ๋‹จ์ด ๋„ค๋น„๊ฒŒ์ด์…˜ ์˜์—ญ์ด ๋˜๋ฏ€๋กœ ์‹œ์Šคํ…œ ์˜์—ญ๊ณผ ์ปจํ…์ธ ๊ฐ€ ๊ฒน์น˜์ง€ ์•Š๊ฒŒ ํ•  ์ˆ˜ ์žˆ์Œ var body: some View { NavigationStack { Form { Section { Text("red") Text("yellow") Text("black") } } .navig..
Form ์• ํ”Œ ๊ณต์‹ ๋ฌธ์„œ ๋ทฐ๋ฅผ ํฌํ•จ ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š” Containe Control์„ ๊ทธ๋ฃนํ•‘ ํ•  ์ˆ˜ ์žˆ์Œ. ํŠน์ • ์ปจํŠธ๋กค์— ๋Œ€ํ•ด ์ง€์ •๋œ UI๋ฅผ ๋ณด์—ฌ์คŒ. ์•„๋ž˜ ๊ธ€ ์ฐธ๊ณ  ์ฃผ๋กœ ์„ค์ •ํ™”๋ฉด์ด๋‚˜ ๊ธฐ๋ณธ ์•ฑ์˜ ๋ฆฌ์ŠคํŠธ์—์„œ ์‚ฌ์šฉ๋จ Form ์˜์—ญ ์Šคํฌ๋กค๋ง ๊ฐ€๋Šฅ struct Form where Content : View ์ฝ”๋“œ ์ „์ฒด ๊นƒ ํ—ˆ๋ธŒ ๋งํฌ Group ํผ์€ ์ตœ๋Œ€ 10๊ฐœ์˜ ๋ทฐ๋ฅผ ํฌํ•จ ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— Group ์„ ์‚ฌ์šฉํ•˜๋ฉด ๋” ๋งŽ์€ ๋ทฐ๋ฅผ ํฌํ•จ ์‹œํ‚ฌ ์ˆ˜ ์žˆ์Œ Form { Group { Text("Hello, world! 1") Text("Hello, world! 2") Text("Hello, world! 3") Text("Hello, world! 4") Text("Hello, world! 5") Text("Hello, world..
Swift 5.1๋ถ€ํ„ฐ ์‚ฌ์šฉ๊ฐ€๋Šฅ getter, setter, computed property ์ฝ”๋“œ ์ค‘๋ณต์„ ์ค„์ผ ์ˆ˜ ์žˆ์Œ ์—ฐ์‚ฐ ํ”„๋กœํผํ‹ฐ ๋กœ์ง์„ ๊ณต์œ ํ•˜๋Š” ๋ฐฉ๋ฒ• ๊ธฐ๋ณธ ์—ฐ์‚ฐ ํ”„๋กœํผํ‹ฐ์˜ ๊ธฐ๋Šฅ์„ ๊ฐœ๋ณ„ ํด๋ž˜์Šค์™€ ๊ตฌ์กฐ์ฒด์™€ ๋ถ„๋ฆฌํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜์—ฌ ์•ฑ ์ฝ”๋“œ์—์„œ ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•จ ํ”„๋กœํผํ‹ฐ ๋ž˜ํผ ๊ตฌํ˜„ @propertyWrapper struct Tenfold { private(set) var num: Int = 0 var wrappedValue: Int { get { num } set { num = newValue * 10 } } init(wrappedValue value: Int) { self.wrappedValue = value } } @propertyWrapper ์ง€์‹œ์ž๋ฅผ ์ด์šฉํ•˜์—ฌ ์„ ์–ธ ํด๋ž˜์Šค๋‚˜ ๊ตฌ์กฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌํ˜„ ๊ฐ€๋Šฅ..
fram
FramiOS ๐Ÿฎ