Ver3.0 ๐ Swift 5 ์ต์ ๋ฌธ๋ฒ๊ณผ SwiftUI๋ก ์์ํ๋ ์ ์ธ์ UI ํ๋ก๊ทธ๋๋ฐ์ ๋ชจ๋ ๊ฒ

๐ Swift 5 ์ต์ ๋ฌธ๋ฒ๊ณผ SwiftUI๋ก ์์ํ๋ ์ ์ธ์ UI ํ๋ก๊ทธ๋๋ฐ์ ๋ชจ๋ ๊ฒ
์น๊ตฌ์ฒ๋ผ ์ฝ๊ณ ์ฌ๋ฏธ์๊ฒ ๋ฐฐ์ฐ๋ ํ๋์ ์ธ iOS ๊ฐ๋ฐ ๊ฐ์ด๋ ๐ฑโจ
์๋ ! ๐ iOS ์ฑ ๊ฐ๋ฐ์ ๊ด์ฌ ์๋ ์น๊ตฌ๋ค, ํน์ SwiftUI๋ผ๋ ๋ง ๋ค์ด๋ดค์ด? 2019๋ ์ ํ์ด WWDC์์ ์ฒ์ ๊ณต๊ฐํ ์ดํ๋ก iOS ๊ฐ๋ฐ ์ํ๊ณ๋ฅผ ์์ ํ ๋ค๋ฐ๊ฟ๋์ ํ์ ์ ์ธ ํ๋ ์์ํฌ์ผ. ๊ธฐ์กด์ UIKit๊ณผ๋ ์์ ํ ๋ค๋ฅธ ์ ๊ทผ ๋ฐฉ์์ผ๋ก, ์ฝ๋ ๋ช ์ค๋ง์ผ๋ก๋ ๋ฉ์ง UI๋ฅผ ๋ง๋ค ์ ์๋ค๋ ๊ฒ ์ ๋ง ๋งค๋ ฅ์ ์ด์ง!
์ค๋์ Swift 5์ ์ต์ ๋ฌธ๋ฒ๊ณผ SwiftUI๋ฅผ ํ์ฉํ ์ ์ธ์ UI ํ๋ก๊ทธ๋๋ฐ์ ๋ํด ๊น์ด ์๊ฒ ํํค์ณ๋ณผ ๊ฑฐ์ผ. ํ๋ก๊ทธ๋๋ฐ์ ์ฒ์ ์์ํ๋ ์ฌ๋๋, ์ด๋ฏธ UIKit์ผ๋ก ๊ฐ๋ฐํ๊ณ ์๋ ๊ฐ๋ฐ์๋ ๋ชจ๋ ์ดํดํ ์ ์๋๋ก ์น์ ํ๊ฒ ์ค๋ช ํด์ค๊ฒ! ๐ฏ
๐ฏ ์ ์ธ์ ํ๋ก๊ทธ๋๋ฐ์ด ๋ญ๊ธธ๋?
๋จผ์ ์ ์ธ์ ํ๋ก๊ทธ๋๋ฐ(Declarative Programming)์ด ๋ญ์ง๋ถํฐ ์์๋ณด์. ์ด๊ฒ SwiftUI์ ํต์ฌ ์ฒ ํ์ด๊ฑฐ๋ ! ๊ฐ๋จํ๊ฒ ๋น์ ํ์๋ฉด ์ด๋ ๊ฒ ์๊ฐํ๋ฉด ๋ผ:
๐ ๋ช ๋ นํ ํ๋ก๊ทธ๋๋ฐ (UIKit ๋ฐฉ์)
"๋ฐ๊ฐ๋ฃจ๋ฅผ ๋ฐ์ฃฝํ๊ณ , ํ ๋งํ ์์ค๋ฅผ ๋ฐ๋ฅด๊ณ , ์น์ฆ๋ฅผ ์ฌ๋ฆฌ๊ณ , ์ค๋ธ์ ๋ฃ๊ณ , 180๋๋ก ์ค์ ํ๊ณ , 15๋ถ ํ์ด๋จธ๋ฅผ ๋ง์ถ๊ณ ..."
๐ ์ ์ธ์ ํ๋ก๊ทธ๋๋ฐ (SwiftUI ๋ฐฉ์)
"ํผ์ ํ๋ ์ฃผ์ธ์!"
๋ช ๋ นํ ํ๋ก๊ทธ๋๋ฐ์ ์ด๋ป๊ฒ(How) ๋ง๋ค์ง๋ฅผ ๋จ๊ณ๋ณ๋ก ์ง์ํ๋ ๋ฐฉ์์ด๊ณ , ์ ์ธ์ ํ๋ก๊ทธ๋๋ฐ์ ๋ฌด์์(What) ์ํ๋์ง๋ง ๋งํ๋ฉด ๋๋ ๊ฑฐ์ผ. SwiftUI๋ ํ์์ ๋ฐฉ์์ ์ฑํํด์ ๊ฐ๋ฐ์๊ฐ UI์ ์ต์ข ์ํ๋ง ์ ์ธํ๋ฉด, ํ๋ ์์ํฌ๊ฐ ์์์ ๊ทธ ์ํ๋ฅผ ๋ง๋ค์ด๋ด๋ ๋ฐฉ์์ผ๋ก ๋์ํด! ๐
์๋ฅผ ๋ค์ด๋ณผ๊น? UIKit์์ ๋ฒํผ ํ๋๋ฅผ ๋ง๋ค๊ณ ํ๋ฉด์ ํ์ํ๋ ค๋ฉด ์ด๋ ๊ฒ ํด์ผ ํ์ด:
// UIKit ๋ฐฉ์ - ๋ช
๋ นํ
let button = UIButton(type: .system)
button.setTitle("ํด๋ฆญํ์ธ์", for: .normal)
button.frame = CGRect(x: 100, y: 100, width: 200, height: 50)
button.backgroundColor = .blue
button.setTitleColor(.white, for: .normal)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
view.addSubview(button)
@objc func buttonTapped() {
print("๋ฒํผ์ด ํด๋ฆญ๋์์ต๋๋ค!")
}
์... ๋ฒํผ ํ๋ ๋ง๋๋๋ฐ ์ด๋ ๊ฒ ๋ง์ ์ฝ๋๊ฐ ํ์ํ์ด. ๊ทผ๋ฐ SwiftUI์์๋?
// SwiftUI ๋ฐฉ์ - ์ ์ธ์
Button("ํด๋ฆญํ์ธ์") {
print("๋ฒํผ์ด ํด๋ฆญ๋์์ต๋๋ค!")
}
.frame(width: 200, height: 50)
.background(Color.blue)
.foregroundColor(.white)
ํจ์ฌ ๊ฐ๊ฒฐํ๊ณ ์ง๊ด์ ์ด์ง? ์ด๊ฒ ๋ฐ๋ก ์ ์ธ์ ํ๋ก๊ทธ๋๋ฐ์ ํ์ด์ผ! ๐
๐ Swift 5์ ํต์ฌ ์ต์ ๋ฌธ๋ฒ๋ค
SwiftUI๋ฅผ ์ ๋๋ก ํ์ฉํ๋ ค๋ฉด Swift 5์ ์ต์ ๋ฌธ๋ฒ๋ค์ ์ดํดํ๋ ๊ฒ ์ ๋ง ์ค์ํด. ํ๋์ฉ ์ดํด๋ณด์!
1๏ธโฃ Property Wrapper (@State, @Binding, @ObservedObject ๋ฑ)
Property Wrapper๋ Swift 5.1์์ ๋์ ๋ ๊ฐ๋ ฅํ ๊ธฐ๋ฅ์ด์ผ. SwiftUI์์๋ ์ด๊ฑธ ํ์ฉํด์ ์ํ ๊ด๋ฆฌ๋ฅผ ์์ฒญ ์ฝ๊ฒ ๋ง๋ค์์ด. @State๋ ๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ Property Wrapper๋ก, View ๋ด๋ถ์ ์ํ๋ฅผ ๊ด๋ฆฌํ ๋ ์ฌ์ฉํด.
struct CounterView: View {
@State private var count = 0
var body: some View {
VStack {
Text("์นด์ดํธ: \(count)")
.font(.largeTitle)
Button("์ฆ๊ฐ") {
count += 1
}
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
}
}
}
์ฌ๊ธฐ์ `@State`๋ฅผ ๋ถ์ด๋ฉด SwiftUI๊ฐ ์ด ๋ณ์์ ๋ณํ๋ฅผ ์๋์ผ๋ก ๊ฐ์งํ๊ณ , ๊ฐ์ด ๋ฐ๋ ๋๋ง๋ค View๋ฅผ ๋ค์ ๊ทธ๋ ค์ค. ๋ง๋ฒ ๊ฐ์ง? โจ
๐ก Pro Tip: @State๋ ํญ์ private์ผ๋ก ์ ์ธํ๋ ๊ฒ ์ข์. ์๋ํ๋ฉด ํด๋น View ๋ด๋ถ์์๋ง ์ฌ์ฉ๋๋ ์ํ์ด๊ธฐ ๋๋ฌธ์ด์ผ. ๋ค๋ฅธ View์ ์ํ๋ฅผ ๊ณต์ ํ๋ ค๋ฉด @Binding์ด๋ @ObservedObject๋ฅผ ์ฌ์ฉํด์ผ ํด!
2๏ธโฃ @Binding - ๋ถ๋ชจ-์์ ๊ฐ ๋ฐ์ดํฐ ๊ณต์
@Binding์ ๋ถ๋ชจ View์ ์ํ๋ฅผ ์์ View์์ ์ฝ๊ณ ์ธ ์ ์๊ฒ ํด์ฃผ๋ Property Wrapper์ผ. ์๋ฐฉํฅ ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ์ด ๊ฐ๋ฅํ๋ค๋ ๊ฒ ํต์ฌ์ด์ง!
struct ParentView: View {
@State private var isOn = false
var body: some View {
VStack {
Text(isOn ? "์ผ์ง ๐ข" : "๊บผ์ง ๐ด")
.font(.title)
ToggleButton(isOn: $isOn)
}
}
}
struct ToggleButton: View {
@Binding var isOn: Bool
var body: some View {
Button(isOn ? "๋๊ธฐ" : "์ผ๊ธฐ") {
isOn.toggle()
}
.padding()
.background(isOn ? Color.green : Color.red)
.foregroundColor(.white)
.cornerRadius(10)
}
}
`$isOn`์ฒ๋ผ ๋ฌ๋ฌ ๊ธฐํธ๋ฅผ ๋ถ์ด๋ฉด Binding์ ์ ๋ฌํ ์ ์์ด. ์์ View์์ ๊ฐ์ ๋ฐ๊พธ๋ฉด ๋ถ๋ชจ View์ ์ํ๋ ์๋์ผ๋ก ์ ๋ฐ์ดํธ๋ผ! ๐
3๏ธโฃ Opaque Return Type (some View)
SwiftUI์์ `some View`๋ผ๋ ํํ์ ์์ฒญ ๋ง์ด ๋ณด๊ฒ ๋ ๊ฑฐ์ผ. ์ด๊ฑด Swift 5.1์์ ๋์ ๋ Opaque Type์ด๋ผ๋ ๊ธฐ๋ฅ์ด์ผ.
var body: some View {
Text("Hello, SwiftUI!")
}
`some View`๋ "์ด ํจ์๋ View ํ๋กํ ์ฝ์ ์ค์ํ๋ ์ด๋ค ๊ตฌ์ฒด์ ์ธ ํ์ ์ ๋ฐํํ๋ค"๋ ์๋ฏธ์ผ. ์ ํํ ์ด๋ค ํ์ ์ธ์ง๋ ์ปดํ์ผ๋ฌ๊ฐ ์์์ ์ถ๋ก ํ๊ฒ ํ๋ ๊ฑฐ์ง. ์ด๋ ๊ฒ ํ๋ฉด ๋ณต์กํ ์ ๋ค๋ฆญ ํ์ ์ ๋ช ์ํ์ง ์์๋ ๋๊ณ , ์ฝ๋๊ฐ ํจ์ฌ ๊น๋ํด์ ธ! ๐จ
4๏ธโฃ Function Builder (@ViewBuilder)
SwiftUI์ ์ ์ธ์ ๋ฌธ๋ฒ์ ๊ฐ๋ฅํ๊ฒ ํ๋ ํต์ฌ ๊ธฐ๋ฅ ์ค ํ๋๊ฐ ๋ฐ๋ก Function Builder์ผ. `@ViewBuilder`๋ฅผ ์ฌ์ฉํ๋ฉด ์ฌ๋ฌ View๋ฅผ ์์ฐ์ค๋ฝ๊ฒ ๋์ดํ ์ ์์ด.
struct ContentView: View {
var body: some View {
VStack {
Text("์ฒซ ๋ฒ์งธ ํ
์คํธ")
Text("๋ ๋ฒ์งธ ํ
์คํธ")
Text("์ธ ๋ฒ์งธ ํ
์คํธ")
if someCondition {
Text("์กฐ๊ฑด๋ถ ํ
์คํธ")
}
}
}
}
VStack ์์์ ์ฌ๋ฌ View๋ฅผ ์ผํ ์์ด ๋์ดํ ์ ์๋ ์ด์ ๊ฐ ๋ฐ๋ก @ViewBuilder ๋๋ถ์ด์ผ. ์ฌ์ง์ด if๋ฌธ๋ ์์ฐ์ค๋ฝ๊ฒ ์ฌ์ฉํ ์ ์์ง! ๐
5๏ธโฃ Combine Framework์์ ํตํฉ
Swift 5์ ํจ๊ป ๋ฑ์ฅํ Combine ํ๋ ์์ํฌ๋ ๋ฐ์ํ ํ๋ก๊ทธ๋๋ฐ์ ๊ฐ๋ฅํ๊ฒ ํด์ค. SwiftUI์ ์๋ฒฝํ๊ฒ ํตํฉ๋์ด ์์ด์, ๋น๋๊ธฐ ๋ฐ์ดํฐ ์ฒ๋ฆฌ๊ฐ ์ ๋ง ์ฌ์์ก์ด.
import Combine
class UserViewModel: ObservableObject {
@Published var username = ""
@Published var isValid = false
private var cancellables = Set<AnyCancellable>()
init() {
$username
.map { $0.count >= 3 }
.assign(to: &$isValid)
}
}
`@Published`๋ฅผ ์ฌ์ฉํ๋ฉด ๊ฐ์ด ๋ณ๊ฒฝ๋ ๋๋ง๋ค ์๋์ผ๋ก ์๋ฆผ์ ๋ณด๋ด๊ณ , SwiftUI๊ฐ View๋ฅผ ์ ๋ฐ์ดํธํด์ค. ์ ๋ง ํธ๋ฆฌํ์ง? ๐
๐๏ธ SwiftUI์ ํต์ฌ ๊ตฌ์ฑ ์์
์ด์ SwiftUI์ ํต์ฌ ๊ตฌ์ฑ ์์๋ค์ ํ๋์ฉ ์ดํด๋ณด์. ์ด๊ฒ๋ค๋ง ์ ๋๋ก ์ดํดํ๋ฉด ์ฌ๋งํ ์ฑ์ ๋ค ๋ง๋ค ์ ์์ด! ๐ช
๐จ ๊ธฐ๋ณธ View ์ปดํฌ๋ํธ๋ค
SwiftUI๋ ๋ค์ํ ๊ธฐ๋ณธ View ์ปดํฌ๋ํธ๋ฅผ ์ ๊ณตํด. ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉํ๋ ๊ฒ๋ค์ ์ ๋ฆฌํด๋ดค์ด:
| ์ปดํฌ๋ํธ | ์ค๋ช | ์ฃผ์ ์ฉ๋ |
|---|---|---|
| Text | ํ ์คํธ ํ์ | ๋ ์ด๋ธ, ์ ๋ชฉ, ๋ณธ๋ฌธ ๋ฑ |
| Image | ์ด๋ฏธ์ง ํ์ | ์์ด์ฝ, ์ฌ์ง, ์ผ๋ฌ์คํธ |
| Button | ๋ฒํผ | ์ฌ์ฉ์ ์ก์ ์ฒ๋ฆฌ |
| TextField | ํ ์คํธ ์ ๋ ฅ | ํผ, ๊ฒ์์ฐฝ ๋ฑ |
| Toggle | ์ค์์น | ์ค์ on/off |
| Slider | ์ฌ๋ผ์ด๋ | ๊ฐ ๋ฒ์ ์ ํ |
| Picker | ์ ํ๊ธฐ | ์ต์ ์ ํ |
| List | ๋ฆฌ์คํธ | ์คํฌ๋กค ๊ฐ๋ฅํ ๋ชฉ๋ก |
์ด ์ปดํฌ๋ํธ๋ค์ ์กฐํฉํ๋ฉด ์ ๋ง ๋ค์ํ UI๋ฅผ ๋ง๋ค ์ ์์ด. ์์ ๋ฅผ ํ๋ ๋ณผ๊น?
struct ProfileView: View {
@State private var username = ""
@State private var age = 25.0
@State private var isSubscribed = false
@State private var selectedColor = "ํ๋์"
let colors = ["๋นจ๊ฐ์", "ํ๋์", "์ด๋ก์", "๋
ธ๋์"]
var body: some View {
Form {
Section(header: Text("๊ธฐ๋ณธ ์ ๋ณด")) {
TextField("์ฌ์ฉ์ ์ด๋ฆ", text: $username)
HStack {
Text("๋์ด: \(Int(age))")
Slider(value: $age, in: 0...100, step: 1)
}
}
Section(header: Text("์ค์ ")) {
Toggle("๊ตฌ๋
ํ๊ธฐ", isOn: $isSubscribed)
Picker("์ข์ํ๋ ์์", selection: $selectedColor) {
ForEach(colors, id: \.self) { color in
Text(color)
}
}
}
Section {
Button("์ ์ฅํ๊ธฐ") {
print("์ฌ์ฉ์ ์ ๋ณด ์ ์ฅ!")
}
.frame(maxWidth: .infinity)
.foregroundColor(.white)
.padding()
.background(Color.blue)
.cornerRadius(10)
}
}
.navigationTitle("ํ๋กํ ์ค์ ")
}
}
์ด๋ ๊ฒ ๋ช ์ค์ ์ฝ๋๋ง์ผ๋ก ์์ ํ ํ๋กํ ์ค์ ํ๋ฉด์ ๋ง๋ค ์ ์์ด! Form์ ์ฌ์ฉํ๋ฉด ์๋์ผ๋ก iOS ์คํ์ผ์ ์ค์ ํ๋ฉด์ด ๋ง๋ค์ด์ง์ง. ์ ๋ง ํธ๋ฆฌํ์ง? ๐
๐ ๋ ์ด์์ ์ปจํ ์ด๋
SwiftUI์ ๋ ์ด์์ ์์คํ ์ ์ ๋ง ์ง๊ด์ ์ด์ผ. ์ธ ๊ฐ์ง ๊ธฐ๋ณธ ์คํ๋ง ์๋ฉด ๋๋ถ๋ถ์ ๋ ์ด์์์ ๊ตฌ์ฑํ ์ ์์ด:
VStack (Vertical Stack) ๐
View๋ค์ ์ธ๋ก๋ก ๋ฐฐ์นํด. ์์์ ์๋๋ก ์์ด๋ ๊ตฌ์กฐ์ผ.
HStack (Horizontal Stack) ๐
View๋ค์ ๊ฐ๋ก๋ก ๋ฐฐ์นํด. ์ผ์ชฝ์์ ์ค๋ฅธ์ชฝ์ผ๋ก ๋์ด๋๋ ๊ตฌ์กฐ์ง.
ZStack (Depth Stack) ๐ญ
View๋ค์ ๊ฒน์ณ์ ๋ฐฐ์นํด. ๋ ์ด์ด์ฒ๋ผ ์์ด๋ ๊ตฌ์กฐ์ผ.
struct LayoutExample: View {
var body: some View {
ZStack {
// ๋ฐฐ๊ฒฝ
Color.blue.opacity(0.3)
.ignoresSafeArea()
VStack(spacing: 20) {
Text("SwiftUI ๋ ์ด์์")
.font(.largeTitle)
.fontWeight(.bold)
HStack(spacing: 15) {
Image(systemName: "star.fill")
.foregroundColor(.yellow)
Text("๋ณ์ 5.0")
Image(systemName: "star.fill")
.foregroundColor(.yellow)
}
HStack {
Button("์ข์์ โค๏ธ") {
print("์ข์์!")
}
.padding()
.background(Color.red)
.foregroundColor(.white)
.cornerRadius(10)
Button("๊ณต์ ๐ค") {
print("๊ณต์ !")
}
.padding()
.background(Color.green)
.foregroundColor(.white)
.cornerRadius(10)
}
}
.padding()
}
}
}
์คํ๋ค์ ์ค์ฒฉํด์ ์ฌ์ฉํ๋ฉด ๋ณต์กํ ๋ ์ด์์๋ ์ฝ๊ฒ ๋ง๋ค ์ ์์ด. UIKit์์ Auto Layout์ผ๋ก ๊ณ ์ํ๋ ์์ ์ด ์๊ฐ๋์ง ์์? ๐
๐ก ๋ ์ด์์ ํ: spacing ํ๋ผ๋ฏธํฐ๋ก ์์ ๊ฐ ๊ฐ๊ฒฉ์ ์กฐ์ ํ๊ณ , alignment ํ๋ผ๋ฏธํฐ๋ก ์ ๋ ฌ ๋ฐฉ์์ ์ค์ ํ ์ ์์ด. ์๋ฅผ ๋ค์ด `VStack(alignment: .leading, spacing: 10)`์ฒ๋ผ ์ฌ์ฉํ๋ฉด ์ผ์ชฝ ์ ๋ ฌ์ 10ํฌ์ธํธ ๊ฐ๊ฒฉ์ผ๋ก ๋ฐฐ์น๋ผ!
๐ญ Modifier - View ๊พธ๋ฏธ๊ธฐ์ ๋ง๋ฒ
Modifier๋ View์ ์ธํ๊ณผ ๋์์ ๋ณ๊ฒฝํ๋ ๋ฉ์๋์ผ. ์ฒด์ด๋ ๋ฐฉ์์ผ๋ก ์ฌ๋ฌ ๊ฐ๋ฅผ ์ฐ๊ฒฐํด์ ์ฌ์ฉํ ์ ์์ด. ์ด๊ฒ SwiftUI์ ์ ๋ง ํฐ ์ฅ์ ์ค ํ๋์ง!
Text("์๋
ํ์ธ์!")
.font(.title)
.fontWeight(.bold)
.foregroundColor(.blue)
.padding()
.background(Color.yellow)
.cornerRadius(15)
.shadow(color: .gray, radius: 5, x: 0, y: 2)
.scaleEffect(1.2)
.rotationEffect(.degrees(5))
์ด๋ ๊ฒ Modifier๋ฅผ ์ฒด์ด๋ํ๋ฉด ์ฝ๋๋ฅผ ์ฝ๊ธฐ๋ ์ฝ๊ณ , ์์๋๋ก ์ ์ฉ๋๋ ๊ฒ ๋ช ํํ๊ฒ ๋ณด์ฌ. ์ฃผ์ํ ์ ์ Modifier์ ์์๊ฐ ์ค์ํ๋ค๋ ๊ฑฐ์ผ! ์๋ฅผ ๋ค์ด padding์ ๋จผ์ ์ฃผ๊ณ background๋ฅผ ์ ์ฉํ๋ ๊ฒ๊ณผ, background๋ฅผ ๋จผ์ ์ฃผ๊ณ padding์ ์ ์ฉํ๋ ๊ฑด ๊ฒฐ๊ณผ๊ฐ ๋ฌ๋ผ.
// ํจ๋ฉ ํ ๋ฐฐ๊ฒฝ - ๋ฐฐ๊ฒฝ์ด ํจ๋ฉ ์์ญ๊น์ง ํฌํจ
Text("์์ 1")
.padding()
.background(Color.blue)
// ๋ฐฐ๊ฒฝ ํ ํจ๋ฉ - ๋ฐฐ๊ฒฝ์ ํ
์คํธ๋ง ๊ฐ์ธ๊ณ ์ธ๋ถ์ ํจ๋ฉ
Text("์์ 2")
.background(Color.blue)
.padding()
์์ฃผ ์ฌ์ฉํ๋ Modifier๋ค์ ์ ๋ฆฌํด๋ดค์ด:
| ์นดํ ๊ณ ๋ฆฌ | Modifier | ์ค๋ช |
|---|---|---|
| ํ ์คํธ | font() | ํฐํธ ํฌ๊ธฐ์ ์คํ์ผ |
| fontWeight() | ํฐํธ ๊ตต๊ธฐ | |
| foregroundColor() | ํ ์คํธ ์์ | |
| ๋ ์ด์์ | padding() | ๋ด๋ถ ์ฌ๋ฐฑ |
| frame() | ํฌ๊ธฐ ์ง์ | |
| offset() | ์์น ์ด๋ | |
| ์คํ์ผ | background() | ๋ฐฐ๊ฒฝ ์์/View |
| cornerRadius() | ๋ชจ์๋ฆฌ ๋ฅ๊ธ๊ฒ | |
| shadow() | ๊ทธ๋ฆผ์ ํจ๊ณผ | |
| ๋ณํ | scaleEffect() | ํฌ๊ธฐ ์กฐ์ |
| rotationEffect() | ํ์ |
๐ ์ํ ๊ด๋ฆฌ์ ๋ชจ๋ ๊ฒ
SwiftUI์์ ๊ฐ์ฅ ์ค์ํ ๊ฐ๋ ์ค ํ๋๊ฐ ๋ฐ๋ก ์ํ ๊ด๋ฆฌ์ผ. ์ฑ์ ๋ฐ์ดํฐ๊ฐ ๋ณ๊ฒฝ๋ ๋ UI๊ฐ ์๋์ผ๋ก ์ ๋ฐ์ดํธ๋๋ ๋ง๋ฒ ๊ฐ์ ์ผ์ด ์ด๋ป๊ฒ ๊ฐ๋ฅํ์ง ์์๋ณด์! โจ
@State - ๋ก์ปฌ ์ํ ๊ด๋ฆฌ
@State๋ View ๋ด๋ถ์์๋ง ์ฌ์ฉ๋๋ ๊ฐ๋จํ ์ํ๋ฅผ ๊ด๋ฆฌํ ๋ ์ฌ์ฉํด. ๊ฐ์ด ๋ณ๊ฒฝ๋๋ฉด ์๋์ผ๋ก View๊ฐ ๋ค์ ๋ ๋๋ง๋ผ.
struct LikeButton: View {
@State private var isLiked = false
@State private var likeCount = 0
var body: some View {
VStack {
Button(action: {
isLiked.toggle()
likeCount += isLiked ? 1 : -1
}) {
HStack {
Image(systemName: isLiked ? "heart.fill" : "heart")
.foregroundColor(isLiked ? .red : .gray)
Text("\(likeCount)")
}
.font(.title)
}
}
.animation(.spring(), value: isLiked)
}
}
๋ฒํผ์ ๋๋ฅด๋ฉด ํํธ ์์ด์ฝ์ด ์ฑ์์ง๊ณ ์นด์ดํธ๊ฐ ์ฆ๊ฐํด. ์คํ๋ง ์ ๋๋ฉ์ด์ ๊น์ง ์๋์ผ๋ก ์ ์ฉ๋์ง! ๐
@Binding - ์๋ฐฉํฅ ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ
๋ถ๋ชจ View์ @State๋ฅผ ์์ View์์ ์์ ํ ์ ์๊ฒ ํด์ฃผ๋ ๊ฒ @Binding์ด์ผ. ์ค์ ์์ ๋ฅผ ๋ณด์:
struct SettingsView: View {
@State private var isDarkMode = false
@State private var fontSize: Double = 16
var body: some View {
VStack(spacing: 30) {
Text("์ค์ ํ๋ฉด")
.font(.system(size: fontSize))
DarkModeToggle(isDarkMode: $isDarkMode)
FontSizeSlider(fontSize: $fontSize)
Text("๋คํฌ ๋ชจ๋: \(isDarkMode ? "์ผ์ง" : "๊บผ์ง")")
Text("ํฐํธ ํฌ๊ธฐ: \(Int(fontSize))")
}
.padding()
.preferredColorScheme(isDarkMode ? .dark : .light)
}
}
struct DarkModeToggle: View {
@Binding var isDarkMode: Bool
var body: some View {
Toggle("๋คํฌ ๋ชจ๋", isOn: $isDarkMode)
.padding()
.background(Color.gray.opacity(0.2))
.cornerRadius(10)
}
}
struct FontSizeSlider: View {
@Binding var fontSize: Double
var body: some View {
VStack {
Text("ํฐํธ ํฌ๊ธฐ ์กฐ์ ")
Slider(value: $fontSize, in: 12...30, step: 1)
}
.padding()
.background(Color.gray.opacity(0.2))
.cornerRadius(10)
}
}
์์ ์ปดํฌ๋ํธ์์ ๊ฐ์ ๋ณ๊ฒฝํ๋ฉด ๋ถ๋ชจ์ ์ํ๋ ์ฆ์ ์ ๋ฐ์ดํธ๋ผ. ์ด๊ฒ ๋ฐ๋ก ๋ฐ์ํ ํ๋ก๊ทธ๋๋ฐ์ ํ์ด์ผ! ๐
@ObservedObject & @StateObject - ๋ณต์กํ ์ํ ๊ด๋ฆฌ
๋ ๋ณต์กํ ๋น์ฆ๋์ค ๋ก์ง์ด๋ ์ฌ๋ฌ View์์ ๊ณต์ ํด์ผ ํ๋ ์ํ๋ ObservableObject ํ๋กํ ์ฝ์ ์ฑํํ ํด๋์ค๋ก ๊ด๋ฆฌํด.
import Combine
class ShoppingCart: ObservableObject {
@Published var items: [String] = []
@Published var totalPrice: Double = 0
func addItem(_ item: String, price: Double) {
items.append(item)
totalPrice += price
}
func removeItem(at index: Int) {
guard index < items.count else { return }
items.remove(at: index)
// ์ค์ ๋ก๋ ๊ฐ๊ฒฉ ์ ๋ณด๋ ํจ๊ป ์ ์ฅํด์ผ ํ์ง๋ง ์์ ๋จ์ํ
totalPrice = max(0, totalPrice - 10)
}
func clearCart() {
items.removeAll()
totalPrice = 0
}
}
struct ShoppingView: View {
@StateObject private var cart = ShoppingCart()
@State private var newItem = ""
var body: some View {
NavigationView {
VStack {
HStack {
TextField("์ํ ์ด๋ฆ", text: $newItem)
.textFieldStyle(RoundedBorderTextFieldStyle())
Button("์ถ๊ฐ") {
if !newItem.isEmpty {
cart.addItem(newItem, price: 10.0)
newItem = ""
}
}
.padding(.horizontal)
.padding(.vertical, 8)
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(8)
}
.padding()
List {
ForEach(cart.items.indices, id: \.self) { index in
HStack {
Text(cart.items[index])
Spacer()
Text("$10.00")
}
}
.onDelete { indexSet in
indexSet.forEach { cart.removeItem(at: $0) }
}
}
HStack {
Text("์ด์ก: $\(String(format: "%.2f", cart.totalPrice))")
.font(.title2)
.fontWeight(.bold)
Spacer()
Button("์ฅ๋ฐ๊ตฌ๋ ๋น์ฐ๊ธฐ") {
cart.clearCart()
}
.foregroundColor(.red)
}
.padding()
}
.navigationTitle("์ฅ๋ฐ๊ตฌ๋ ๐")
}
}
}
โ ๏ธ @StateObject vs @ObservedObject ์ฐจ์ด์ :
โข @StateObject: View๊ฐ ๊ฐ์ฒด์ ์๋ช ์ฃผ๊ธฐ๋ฅผ ์์ . View๊ฐ ์์ฑ๋ ๋ ๊ฐ์ฒด๋ ์์ฑ๋๊ณ , View๊ฐ ์ฌ๋ผ์ง๋ฉด ๊ฐ์ฒด๋ ํด์ ๋ผ.
โข @ObservedObject: ์ธ๋ถ์์ ์์ฑ๋ ๊ฐ์ฒด๋ฅผ ๊ด์ฐฐ๋ง ํจ. ๊ฐ์ฒด์ ์๋ช ์ฃผ๊ธฐ๋ฅผ ๊ด๋ฆฌํ์ง ์์.
์ผ๋ฐ์ ์ผ๋ก ๊ฐ์ฒด๋ฅผ ์ฒ์ ์์ฑํ๋ ๊ณณ์์๋ @StateObject๋ฅผ, ์ ๋ฌ๋ฐ์์ ์ฌ์ฉํ๋ ๊ณณ์์๋ @ObservedObject๋ฅผ ์ฌ์ฉํด!
@EnvironmentObject - ์ ์ญ ์ํ ๊ด๋ฆฌ
์ฑ ์ ์ฒด์์ ๊ณต์ ํด์ผ ํ๋ ์ํ๋ @EnvironmentObject๋ฅผ ์ฌ์ฉํ๋ฉด ํธ๋ฆฌํด. ์ค๊ฐ View๋ค์ ๊ฑฐ์น์ง ์๊ณ ๋ ๊น์ ๊ณ์ธต์ View์ ๋ฐ์ดํฐ๋ฅผ ์ ๋ฌํ ์ ์์ด.
class UserSettings: ObservableObject {
@Published var username = "Guest"
@Published var isLoggedIn = false
@Published var theme = "Light"
}
@main
struct MyApp: App {
@StateObject private var settings = UserSettings()
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(settings)
}
}
}
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
WelcomeView()
SettingsButton()
}
}
}
}
struct WelcomeView: View {
@EnvironmentObject var settings: UserSettings
var body: some View {
Text("ํ์ํฉ๋๋ค, \(settings.username)๋!")
.font(.title)
.padding()
}
}
struct SettingsButton: View {
@EnvironmentObject var settings: UserSettings
var body: some View {
Button("๋ก๊ทธ์ธ") {
settings.username = "ํ๊ธธ๋"
settings.isLoggedIn = true
}
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
}
}
WelcomeView์ SettingsButton์ด ๊ฐ์ UserSettings ๊ฐ์ฒด๋ฅผ ๊ณต์ ํ์ง๋ง, ContentView๋ฅผ ๊ฑฐ์น์ง ์์๋ ๋ผ. ์ ๋ง ํธ๋ฆฌํ์ง? ๐
๐ฌ ์ ๋๋ฉ์ด์ ๊ณผ ํธ๋์ง์
SwiftUI์ ์ ๋๋ฉ์ด์ ์์คํ ์ ์ ๋ง ๊ฐ๋ ฅํด! ๋ช ์ค์ ์ฝ๋๋ง์ผ๋ก๋ ๋ถ๋๋ฝ๊ณ ์์ฐ์ค๋ฌ์ด ์ ๋๋ฉ์ด์ ์ ๋ง๋ค ์ ์์ด. ์ด๊ฒ ๋ฐ๋ก SwiftUI์ ๋ ๋ค๋ฅธ ๋งค๋ ฅ ํฌ์ธํธ์ง! ๐ซ
์์์ ์ ๋๋ฉ์ด์ (Implicit Animation)
`.animation()` modifier๋ฅผ ์ฌ์ฉํ๋ฉด ํด๋น View์ ๋ชจ๋ ์ํ ๋ณํ๊ฐ ์๋์ผ๋ก ์ ๋๋ฉ์ด์ ๋ผ.
struct PulsingHeart: View {
@State private var isPulsing = false
var body: some View {
Image(systemName: "heart.fill")
.font(.system(size: 100))
.foregroundColor(.red)
.scaleEffect(isPulsing ? 1.3 : 1.0)
.animation(.easeInOut(duration: 0.8).repeatForever(autoreverses: true),
value: isPulsing)
.onAppear {
isPulsing = true
}
}
}
ํํธ๊ฐ ๊ณ์ ์ปค์ก๋ค ์์์ก๋ค ํ๋ฉด์ ๋ฐ๋ ๊ฒ์ฒ๋ผ ๋ณด์ฌ! ๐ `.repeatForever()`๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฌดํ ๋ฐ๋ณต ์ ๋๋ฉ์ด์ ์ ๋ง๋ค ์ ์์ด.
๋ช ์์ ์ ๋๋ฉ์ด์ (Explicit Animation)
`withAnimation` ๋ธ๋ก ์์์ ์ํ๋ฅผ ๋ณ๊ฒฝํ๋ฉด, ๊ทธ ๋ณํ๋ง ์ ๋๋ฉ์ด์ ์ด ์ ์ฉ๋ผ. ๋ ์ธ๋ฐํ ์ ์ด๊ฐ ๊ฐ๋ฅํ์ง!
struct RotatingSquare: View {
@State private var rotation: Double = 0
@State private var color = Color.blue
var body: some View {
VStack(spacing: 30) {
Rectangle()
.fill(color)
.frame(width: 150, height: 150)
.rotationEffect(.degrees(rotation))
HStack(spacing: 20) {
Button("ํ์ ") {
withAnimation(.spring(response: 0.5, dampingFraction: 0.6)) {
rotation += 90
}
}
.buttonStyle(.borderedProminent)
Button("์์ ๋ณ๊ฒฝ") {
withAnimation(.easeInOut(duration: 0.3)) {
color = color == .blue ? .red : .blue
}
}
.buttonStyle(.borderedProminent)
}
}
}
}
ํ์ ๊ณผ ์์ ๋ณ๊ฒฝ์ด ๊ฐ๊ฐ ๋ค๋ฅธ ์ ๋๋ฉ์ด์ ํ์ ์ผ๋ก ์ ์ฉ๋ผ. ์คํ๋ง ์ ๋๋ฉ์ด์ ์ ๋ฌผ๋ฆฌ์ ์ผ๋ก ์์ฐ์ค๋ฌ์ด ์์ง์์ ๋ง๋ค์ด์ค! ๐
ํธ๋์ง์ (Transition)
View๊ฐ ๋ํ๋๊ฑฐ๋ ์ฌ๋ผ์ง ๋์ ํจ๊ณผ๋ฅผ ์ ์ํ๋ ๊ฒ ํธ๋์ง์ ์ด์ผ. ์ ๋ง ๋ค์ํ ํจ๊ณผ๋ฅผ ๋ง๋ค ์ ์์ด!
struct TransitionExample: View {
@State private var showDetails = false
var body: some View {
VStack(spacing: 20) {
Button("์์ธ ์ ๋ณด \(showDetails ? "์จ๊ธฐ๊ธฐ" : "๋ณด๊ธฐ")") {
withAnimation(.spring()) {
showDetails.toggle()
}
}
.buttonStyle(.borderedProminent)
if showDetails {
VStack(alignment: .leading, spacing: 10) {
Text("๐ SwiftUI๋ ์ ๋ง ๋ฉ์ ธ์!")
.font(.headline)
Text("์ ์ธ์ ๋ฌธ๋ฒ์ผ๋ก UI๋ฅผ ์ฝ๊ฒ ๋ง๋ค ์ ์์ด์.")
Text("์ ๋๋ฉ์ด์
๋ ๊ฐ๋จํ๊ฒ ์ถ๊ฐํ ์ ์์ฃ !")
}
.padding()
.background(Color.blue.opacity(0.1))
.cornerRadius(15)
.transition(.asymmetric(
insertion: .scale.combined(with: .opacity),
removal: .slide.combined(with: .opacity)
))
}
}
.padding()
}
}
๋ํ๋ ๋๋ ํฌ๊ธฐ๊ฐ ์ปค์ง๋ฉด์ ํ์ด๋์ธ๋๊ณ , ์ฌ๋ผ์ง ๋๋ ์ฌ๋ผ์ด๋ํ๋ฉด์ ํ์ด๋์์๋ผ. `.asymmetric`์ ์ฌ์ฉํ๋ฉด ๋ฑ์ฅ๊ณผ ํด์ฅ ํจ๊ณผ๋ฅผ ๋ค๋ฅด๊ฒ ์ค์ ํ ์ ์์ด! ๐ญ
๐ก ์ ๋๋ฉ์ด์ ์ฑ๋ฅ ํ:
โข ๋ณต์กํ ์ ๋๋ฉ์ด์ ์ `.drawingGroup()` modifier๋ฅผ ์ฌ์ฉํ๋ฉด ์ฑ๋ฅ์ด ํฅ์๋ผ
โข ๋ง์ ์์๋ฅผ ๋์์ ์ ๋๋ฉ์ด์ ํ ๋๋ `.animation(_:value:)` ํํ๋ก ํน์ ๊ฐ์๋ง ๋ฐ์ํ๋๋ก ํด
โข ๋ถํ์ํ ์ ๋๋ฉ์ด์ ์ ์ ๊ฑฐํด์ ๋ฐฐํฐ๋ฆฌ ์๋ชจ๋ฅผ ์ค์ฌ
์ปค์คํ ์ ๋๋ฉ์ด์
๊ธฐ๋ณธ ์ ๊ณต๋๋ ์ ๋๋ฉ์ด์ ์ธ์๋ ์์ ํ ์ปค์คํ ํ ์ ๋๋ฉ์ด์ ์ ๋ง๋ค ์ ์์ด!
struct WaveAnimation: View {
@State private var waveOffset: CGFloat = 0
var body: some View {
ZStack {
ForEach(0..<5) { index in
Circle()
.stroke(Color.blue.opacity(0.3), lineWidth: 3)
.frame(width: 100 + CGFloat(index) * 30)
.scaleEffect(1 + waveOffset * CGFloat(index) * 0.1)
.opacity(1 - waveOffset * 0.8)
}
}
.onAppear {
withAnimation(.easeInOut(duration: 2).repeatForever(autoreverses: false)) {
waveOffset = 1
}
}
}
}
๋ฌผ๊ฒฐ ํจ๊ณผ๊ฐ ํผ์ ธ๋๊ฐ๋ ์ ๋๋ฉ์ด์ ์ด์ผ. ์ฌ๋ฌ ์์ ๊ฒน์ณ์ ์์ฐจ์ ์ผ๋ก ํฌ๊ธฐ์ ํฌ๋ช ๋๋ฅผ ์กฐ์ ํ๋ฉด ์ด๋ฐ ๋ฉ์ง ํจ๊ณผ๋ฅผ ๋ง๋ค ์ ์์ด! ๐
๐งญ ๋ค๋น๊ฒ์ด์ ๊ณผ ํ๋ฉด ์ ํ
์ฑ์์ ์ฌ๋ฌ ํ๋ฉด์ ์ค๊ฐ๋ ๊ฑด ํ์ ๊ธฐ๋ฅ์ด์ง! SwiftUI๋ ๋ค๋น๊ฒ์ด์ ๋ ์ ๋ง ์ฝ๊ฒ ๋ง๋ค ์ ์์ด. iOS 16๋ถํฐ๋ ๋์ฑ ๊ฐ๋ ฅํ NavigationStack์ด ๋์ ๋์ด! ๐
NavigationStack (iOS 16+)
์ต์ ๋ฐฉ์์ ๋ค๋น๊ฒ์ด์ ์ NavigationStack์ ์ฌ์ฉํด. ํ์ ์ธ์ดํํ๊ณ ๋ ์ ์ฐํ ๋ค๋น๊ฒ์ด์ ์ด ๊ฐ๋ฅํด์ก์ด!
struct NavigationExample: View {
@State private var path = NavigationPath()
var body: some View {
NavigationStack(path: $path) {
List {
NavigationLink("ํ๋กํ", value: "profile")
NavigationLink("์ค์ ", value: "settings")
NavigationLink("์๋ฆผ", value: "notifications")
}
.navigationTitle("๋ฉ์ธ ๋ฉ๋ด")
.navigationDestination(for: String.self) { destination in
switch destination {
case "profile":
ProfileView(path: $path)
case "settings":
SettingsView()
case "notifications":
NotificationsView()
default:
Text("์ ์ ์๋ ํ๋ฉด")
}
}
}
}
}
struct ProfileView: View {
@Binding var path: NavigationPath
var body: some View {
VStack(spacing: 20) {
Image(systemName: "person.circle.fill")
.font(.system(size: 100))
.foregroundColor(.blue)
Text("ํ๊ธธ๋")
.font(.title)
Button("์์ธ ์ ๋ณด ๋ณด๊ธฐ") {
path.append("profile-detail")
}
.buttonStyle(.borderedProminent)
Button("๋ฉ์ธ์ผ๋ก ๋์๊ฐ๊ธฐ") {
path.removeLast(path.count)
}
.buttonStyle(.bordered)
}
.navigationTitle("ํ๋กํ")
}
}
NavigationPath๋ฅผ ์ฌ์ฉํ๋ฉด ํ๋ก๊ทธ๋๋ฐ ๋ฐฉ์์ผ๋ก ๋ค๋น๊ฒ์ด์ ์ ์์ ํ ์ ์ดํ ์ ์์ด. ๋ฅ๋งํฌ ๊ตฌํ์ด๋ ๋ณต์กํ ๋ค๋น๊ฒ์ด์ ํ๋ก์ฐ๋ฅผ ๋ง๋ค ๋ ์ ๋ง ์ ์ฉํด! ๐ฏ
Sheet์ FullScreenCover
๋ชจ๋ฌ ๋ฐฉ์์ผ๋ก ํ๋ฉด์ ๋์ธ ๋๋ sheet๋ fullScreenCover๋ฅผ ์ฌ์ฉํด.
struct ModalExample: View {
@State private var showSheet = false
@State private var showFullScreen = false
var body: some View {
VStack(spacing: 20) {
Button("Sheet ์ด๊ธฐ") {
showSheet = true
}
.buttonStyle(.borderedProminent)
Button("์ ์ฒด ํ๋ฉด ์ด๊ธฐ") {
showFullScreen = true
}
.buttonStyle(.borderedProminent)
}
.sheet(isPresented: $showSheet) {
SheetContentView(isPresented: $showSheet)
}
.fullScreenCover(isPresented: $showFullScreen) {
FullScreenContentView(isPresented: $showFullScreen)
}
}
}
struct SheetContentView: View {
@Binding var isPresented: Bool
var body: some View {
NavigationView {
VStack {
Text("์ด๊ฒ์ Sheet์
๋๋ค!")
.font(.title)
.padding()
Text("์๋๋ก ๋๋๊ทธํ๊ฑฐ๋ ๋ซ๊ธฐ ๋ฒํผ์ ๋๋ฌ ๋ซ์ ์ ์์ด์.")
.multilineTextAlignment(.center)
.padding()
}
.navigationTitle("Sheet")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button("๋ซ๊ธฐ") {
isPresented = false
}
}
}
}
}
}
struct FullScreenContentView: View {
@Binding var isPresented: Bool
var body: some View {
ZStack {
Color.blue.ignoresSafeArea()
VStack {
Text("์ ์ฒด ํ๋ฉด ๋ชจ๋!")
.font(.largeTitle)
.foregroundColor(.white)
Button("๋ซ๊ธฐ") {
isPresented = false
}
.padding()
.background(Color.white)
.foregroundColor(.blue)
.cornerRadius(10)
}
}
}
}
Sheet๋ ๋ถ๋ถ ํ๋ฉด์ผ๋ก ์ฌ๋ผ์ค๊ณ ๋๋๊ทธ๋ก ๋ซ์ ์ ์์ง๋ง, FullScreenCover๋ ์ ์ฒด ํ๋ฉด์ ๋ฎ์ด์ ๋ช ์์ ์ผ๋ก ๋ซ์์ผ ํด. ์ฉ๋์ ๋ง๊ฒ ์ ํํด์ ์ฌ์ฉํ๋ฉด ๋ผ! ๐ฑ
TabView - ํญ ๊ธฐ๋ฐ ๋ค๋น๊ฒ์ด์
๋ง์ ์ฑ๋ค์ด ์ฌ์ฉํ๋ ํ๋จ ํญ ๋ฐ๋ SwiftUI์์๋ ์ ๋ง ์ฝ๊ฒ ๋ง๋ค ์ ์์ด!
struct MainTabView: View {
@State private var selectedTab = 0
var body: some View {
TabView(selection: $selectedTab) {
HomeView()
.tabItem {
Label("ํ", systemImage: "house.fill")
}
.tag(0)
SearchView()
.tabItem {
Label("๊ฒ์", systemImage: "magnifyingglass")
}
.tag(1)
FavoritesView()
.tabItem {
Label("์ฆ๊ฒจ์ฐพ๊ธฐ", systemImage: "heart.fill")
}
.tag(2)
ProfileView()
.tabItem {
Label("ํ๋กํ", systemImage: "person.fill")
}
.tag(3)
}
.accentColor(.blue)
}
}
struct HomeView: View {
var body: some View {
NavigationStack {
ScrollView {
VStack(spacing: 20) {
ForEach(1...10, id: \.self) { index in
CardView(title: "์นด๋ \(index)")
}
}
.padding()
}
.navigationTitle("ํ")
}
}
}
struct CardView: View {
let title: String
var body: some View {
VStack(alignment: .leading) {
Text(title)
.font(.headline)
Text("SwiftUI๋ก ๋ง๋ ๋ฉ์ง ์นด๋ ์ปดํฌ๋ํธ์
๋๋ค!")
.font(.subheadline)
.foregroundColor(.secondary)
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
.background(Color.gray.opacity(0.1))
.cornerRadius(12)
}
}
TabView๋ฅผ ์ฌ์ฉํ๋ฉด iOS ํ์ค ํญ ๋ฐ ์ธํฐํ์ด์ค๋ฅผ ์ฝ๊ฒ ๊ตฌํํ ์ ์์ด. ๊ฐ ํญ๋ง๋ค ๋ ๋ฆฝ์ ์ธ ๋ค๋น๊ฒ์ด์ ์คํ์ ๊ฐ์ง ์๋ ์์ง! ๐จ
๐ List์ ๋ฐ์ดํฐ ํ์
๋ฐ์ดํฐ๋ฅผ ๋ฆฌ์คํธ๋ก ํ์ํ๋ ๊ฑด ์ฑ ๊ฐ๋ฐ์์ ์ ๋ง ์์ฃผ ํ๋ ์์ ์ด์ผ. SwiftUI์ List๋ UITableView๋ณด๋ค ํจ์ฌ ์ฌ์ฉํ๊ธฐ ์ฌ์! ๐
๊ธฐ๋ณธ List ์ฌ์ฉ๋ฒ
struct Todo: Identifiable {
let id = UUID()
var title: String
var isCompleted: Bool
}
struct TodoListView: View {
@State private var todos = [
Todo(title: "SwiftUI ๊ณต๋ถํ๊ธฐ", isCompleted: false),
Todo(title: "์ฑ ํ๋กํ ํ์
๋ง๋ค๊ธฐ", isCompleted: false),
Todo(title: "์ฌ๋ฅ๋ท์์ ํ๋ก๊ทธ๋๋ฐ ๊ฐ์ ์ฐพ๊ธฐ", isCompleted: true),
Todo(title: "์ฝ๋ ๋ฆฌ๋ทฐํ๊ธฐ", isCompleted: false)
]
@State private var newTodoTitle = ""
var body: some View {
NavigationStack {
VStack {
HStack {
TextField("์ ํ ์ผ", text: $newTodoTitle)
.textFieldStyle(RoundedBorderTextFieldStyle())
Button(action: addTodo) {
Image(systemName: "plus.circle.fill")
.font(.title2)
}
.disabled(newTodoTitle.isEmpty)
}
.padding()
List {
ForEach($todos) { $todo in
HStack {
Button(action: {
todo.isCompleted.toggle()
}) {
Image(systemName: todo.isCompleted ?
"checkmark.circle.fill" : "circle")
.foregroundColor(todo.isCompleted ? .green : .gray)
}
Text(todo.title)
.strikethrough(todo.isCompleted)
.foregroundColor(todo.isCompleted ? .gray : .primary)
}
}
.onDelete(perform: deleteTodos)
.onMove(perform: moveTodos)
}
.listStyle(.insetGrouped)
}
.navigationTitle("ํ ์ผ ๋ชฉ๋ก โ
")
.toolbar {
EditButton()
}
}
}
func addTodo() {
guard !newTodoTitle.isEmpty else { return }
todos.append(Todo(title: newTodoTitle, isCompleted: false))
newTodoTitle = ""
}
func deleteTodos(at offsets: IndexSet) {
todos.remove(atOffsets: offsets)
}
func moveTodos(from source: IndexSet, to destination: Int) {
todos.move(fromOffsets: source, toOffset: destination)
}
}
`.onDelete`์ `.onMove`๋ฅผ ์ฌ์ฉํ๋ฉด ์ค์์ดํ ์ญ์ ์ ๋๋๊ทธ ์ค ๋๋กญ ์ฌ์ ๋ ฌ์ด ์๋์ผ๋ก ๊ตฌํ๋ผ. UITableView์์ ๋ธ๋ฆฌ๊ฒ์ดํธ ๋ฉ์๋ ์์ญ ์ค ์์ฑํ๋ ๊ฒ ์๊ฐ๋์ง? ๐
Section์ ํ์ฉํ ๊ทธ๋ฃนํ
struct GroupedListView: View {
let completedTodos: [Todo]
let incompleteTodos: [Todo]
var body: some View {
List {
if !incompleteTodos.isEmpty {
Section(header: Text("์งํ ์ค ๐ฅ")) {
ForEach(incompleteTodos) { todo in
TodoRow(todo: todo)
}
}
}
if !completedTodos.isEmpty {
Section(header: Text("์๋ฃ โ
")) {
ForEach(completedTodos) { todo in
TodoRow(todo: todo)
}
}
}
}
}
}
struct TodoRow: View {
let todo: Todo
var body: some View {
HStack {
Image(systemName: todo.isCompleted ?
"checkmark.circle.fill" : "circle")
.foregroundColor(todo.isCompleted ? .green : .gray)
Text(todo.title)
}
}
}
Section์ ์ฌ์ฉํ๋ฉด ๋ฐ์ดํฐ๋ฅผ ๋ ผ๋ฆฌ์ ์ผ๋ก ๊ทธ๋ฃนํํด์ ๋ณด์ฌ์ค ์ ์์ด. ํค๋์ ํธํฐ๋ ์ฝ๊ฒ ์ถ๊ฐํ ์ ์์ง! ๐
LazyVStack๊ณผ ์ฑ๋ฅ ์ต์ ํ
๋ง์ ์์ ๋ฐ์ดํฐ๋ฅผ ํ์ํ ๋๋ LazyVStack์ด๋ LazyHStack์ ์ฌ์ฉํ๋ฉด ์ฑ๋ฅ์ด ์ข์์ ธ. ํ๋ฉด์ ๋ณด์ด๋ ๋ถ๋ถ๋ง ๋ ๋๋งํ๊ฑฐ๋ !
struct InfiniteScrollView: View {
@State private var items = Array(1...50)
@State private var isLoading = false
var body: some View {
ScrollView {
LazyVStack(spacing: 15) {
ForEach(items, id: \.self) { item in
ItemCard(number: item)
.onAppear {
if item == items.last {
loadMore()
}
}
}
if isLoading {
ProgressView()
.padding()
}
}
.padding()
}
}
func loadMore() {
guard !isLoading else { return }
isLoading = true
// ์ค์ ๋ก๋ ๋คํธ์ํฌ ์์ฒญ
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
let newItems = (items.count + 1)...(items.count + 20)
items.append(contentsOf: newItems)
isLoading = false
}
}
}
struct ItemCard: View {
let number: Int
var body: some View {
HStack {
Image(systemName: "\(number).circle.fill")
.font(.largeTitle)
.foregroundColor(.blue)
VStack(alignment: .leading) {
Text("์์ดํ
#\(number)")
.font(.headline)
Text("LazyVStack์ผ๋ก ์ต์ ํ๋ ๋ฆฌ์คํธ")
.font(.caption)
.foregroundColor(.secondary)
}
Spacer()
}
.padding()
.background(Color.gray.opacity(0.1))
.cornerRadius(12)
}
}
๋ฌดํ ์คํฌ๋กค ๊ตฌํ๋ ์ด๋ ๊ฒ ๊ฐ๋จํด! `.onAppear`๋ฅผ ํ์ฉํ๋ฉด ๋ง์ง๋ง ์์ดํ ์ด ๋ณด์ผ ๋ ์๋์ผ๋ก ๋ค์ ๋ฐ์ดํฐ๋ฅผ ๋ก๋ํ ์ ์์ด. ๐
๐จ ์ปค์คํ View์ ์ฌ์ฌ์ฉ์ฑ
SwiftUI์ ์ง์ง ํ์ ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ์ปดํฌ๋ํธ๋ฅผ ์ฝ๊ฒ ๋ง๋ค ์ ์๋ค๋ ๊ฑฐ์ผ. ํ ๋ฒ ๋ง๋ค์ด๋๋ฉด ์ฑ ์ ์ฒด์์ ์ผ๊ด๋ ๋์์ธ์ ์ ์งํ ์ ์์ง! โจ
์ปค์คํ Button ์คํ์ผ
struct PrimaryButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.font(.headline)
.foregroundColor(.white)
.padding()
.frame(maxWidth: .infinity)
.background(
LinearGradient(
colors: [.blue, .purple],
startPoint: .leading,
endPoint: .trailing
)
)
.cornerRadius(12)
.scaleEffect(configuration.isPressed ? 0.95 : 1.0)
.animation(.easeInOut(duration: 0.2), value: configuration.isPressed)
}
}
struct SecondaryButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.font(.headline)
.foregroundColor(.blue)
.padding()
.frame(maxWidth: .infinity)
.background(Color.blue.opacity(0.1))
.cornerRadius(12)
.overlay(
RoundedRectangle(cornerRadius: 12)
.stroke(Color.blue, lineWidth: 2)
)
.scaleEffect(configuration.isPressed ? 0.95 : 1.0)
}
}
// ์ฌ์ฉ ์์
struct ButtonStyleExample: View {
var body: some View {
VStack(spacing: 20) {
Button("Primary Button") {
print("Primary ํด๋ฆญ!")
}
.buttonStyle(PrimaryButtonStyle())
Button("Secondary Button") {
print("Secondary ํด๋ฆญ!")
}
.buttonStyle(SecondaryButtonStyle())
}
.padding()
}
}
ButtonStyle ํ๋กํ ์ฝ์ ์ฑํํ๋ฉด ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ๋ฒํผ ์คํ์ผ์ ๋ง๋ค ์ ์์ด. ์ฑ ์ ์ฒด์์ ์ผ๊ด๋ ๋ฒํผ ๋์์ธ์ ์ ์งํ๊ธฐ ์ ๋ง ์ข์! ๐ฏ
View Modifier ํ์ฅ
struct CardModifier: ViewModifier {
func body(content: Content) -> some View {
content
.padding()
.background(Color.white)
.cornerRadius(15)
.shadow(color: .gray.opacity(0.3), radius: 5, x: 0, y: 2)
}
}
extension View {
func cardStyle() -> some View {
modifier(CardModifier())
}
}
// ๋ ํธ๋ฆฌํ ์ฌ์ฉ์ ์ํ ์ถ๊ฐ ํ์ฅ
extension View {
func glowEffect(color: Color = .blue, radius: CGFloat = 10) -> some View {
self
.shadow(color: color.opacity(0.6), radius: radius, x: 0, y: 0)
.shadow(color: color.opacity(0.3), radius: radius * 2, x: 0, y: 0)
}
func shimmerEffect() -> some View {
self
.overlay(
GeometryReader { geometry in
Rectangle()
.fill(
LinearGradient(
colors: [.clear, .white.opacity(0.5), .clear],
startPoint: .leading,
endPoint: .trailing
)
)
.frame(width: geometry.size.width * 0.3)
.offset(x: -geometry.size.width)
}
)
}
}
// ์ฌ์ฉ ์์
struct CustomModifierExample: View {
var body: some View {
VStack(spacing: 20) {
Text("์นด๋ ์คํ์ผ ์ ์ฉ")
.cardStyle()
Text("๋น๋๋ ํจ๊ณผ")
.font(.title)
.glowEffect(color: .purple, radius: 15)
Rectangle()
.fill(Color.gray.opacity(0.3))
.frame(height: 100)
.shimmerEffect()
.cardStyle()
}
.padding()
}
}
ViewModifier๋ฅผ ๋ง๋ค๊ณ View extension์ผ๋ก ํธ๋ฆฌํ๊ฒ ์ฌ์ฉํ ์ ์์ด. ์ด๋ ๊ฒ ํ๋ฉด ์ฝ๋ ์ฌ์ฌ์ฉ์ฑ์ด ์์ฒญ ๋์์ง์ง! ๐
์ ๋ค๋ฆญ์ ํ์ฉํ ์ฌ์ฌ์ฉ ์ปดํฌ๋ํธ
struct LoadingView<Content: View>: View {
let isLoading: Bool
let content: () -> Content
var body: some View {
ZStack {
content()
.disabled(isLoading)
.blur(radius: isLoading ? 3 : 0)
if isLoading {
VStack(spacing: 15) {
ProgressView()
.scaleEffect(1.5)
Text("๋ก๋ฉ ์ค...")
.font(.headline)
}
.padding(30)
.background(Color.white)
.cornerRadius(15)
.shadow(radius: 10)
}
}
}
}
struct EmptyStateView<Content: View>: View {
let isEmpty: Bool
let emptyMessage: String
let emptyIcon: String
let content: () -> Content
var body: some View {
Group {
if isEmpty {
VStack(spacing: 20) {
Image(systemName: emptyIcon)
.font(.system(size: 60))
.foregroundColor(.gray)
Text(emptyMessage)
.font(.headline)
.foregroundColor(.gray)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else {
content()
}
}
}
}
// ์ฌ์ฉ ์์
struct DataListView: View {
@State private var items: [String] = []
@State private var isLoading = false
var body: some View {
LoadingView(isLoading: isLoading) {
EmptyStateView(
isEmpty: items.isEmpty,
emptyMessage: "๋ฐ์ดํฐ๊ฐ ์์ต๋๋ค",
emptyIcon: "tray"
) {
List(items, id: \.self) { item in
Text(item)
}
}
}
.onAppear {
loadData()
}
}
func loadData() {
isLoading = true
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
items = ["ํญ๋ชฉ 1", "ํญ๋ชฉ 2", "ํญ๋ชฉ 3"]
isLoading = false
}
}
}
์ ๋ค๋ฆญ์ ํ์ฉํ๋ฉด ์ด๋ค Content๋ ๋ฐ์ ์ ์๋ ์ ์ฐํ ์ปดํฌ๋ํธ๋ฅผ ๋ง๋ค ์ ์์ด. ๋ก๋ฉ ์ํ๋ ๋น ์ํ ์ฒ๋ฆฌ๋ฅผ ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ์ปดํฌ๋ํธ๋ก ๋ง๋ค๋ฉด ์ ๋ง ํธ๋ฆฌํด! ๐ช
๐ ๋คํธ์ํน๊ณผ ๋น๋๊ธฐ ์ฒ๋ฆฌ
์ค์ ์ฑ์ ๋ง๋ค ๋๋ ์๋ฒ์ ํต์ ํ๋ ๊ฒ ํ์์ง! Swift 5.5๋ถํฐ ๋์ ๋ async/await๋ฅผ SwiftUI์ ํจ๊ป ์ฌ์ฉํ๋ฉด ๋น๋๊ธฐ ์ฝ๋๋ฅผ ์ ๋ง ๊น๋ํ๊ฒ ์์ฑํ ์ ์์ด. ๐ฅ
async/await๋ฅผ ํ์ฉํ ๋คํธ์ํน
struct User: Codable, Identifiable {
let id: Int
let name: String
let email: String
}
class UserViewModel: ObservableObject {
@Published var users: [User] = []
@Published var isLoading = false
@Published var errorMessage: String?
func fetchUsers() async {
isLoading = true
errorMessage = nil
do {
let url = URL(string: "https://jsonplaceholder.typicode.com/users")!
let (data, _) = try await URLSession.shared.data(from: url)
let decodedUsers = try JSONDecoder().decode([User].self, from: data)
await MainActor.run {
self.users = decodedUsers
self.isLoading = false
}
} catch {
await MainActor.run {
self.errorMessage = "๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์ค๋๋ฐ ์คํจํ์ต๋๋ค: \(error.localizedDescription)"
self.isLoading = false
}
}
}
}
struct UserListView: View {
@StateObject private var viewModel = UserViewModel()
var body: some View {
NavigationStack {
Group {
if viewModel.isLoading {
ProgressView("์ฌ์ฉ์ ์ ๋ณด ๋ก๋ฉ ์ค...")
} else if let error = viewModel.errorMessage {
VStack(spacing: 15) {
Image(systemName: "exclamationmark.triangle")
.font(.system(size: 50))
.foregroundColor(.red)
Text(error)
.multilineTextAlignment(.center)
Button("๋ค์ ์๋") {
Task {
await viewModel.fetchUsers()
}
}
.buttonStyle(.borderedProminent)
}
.padding()
} else {
List(viewModel.users) { user in
VStack(alignment: .leading, spacing: 5) {
Text(user.name)
.font(.headline)
Text(user.email)
.font(.caption)
.foregroundColor(.secondary)
}
}
}
}
.navigationTitle("์ฌ์ฉ์ ๋ชฉ๋ก")
.task {
await viewModel.fetchUsers()
}
}
}
}
`.task` modifier๋ฅผ ์ฌ์ฉํ๋ฉด View๊ฐ ๋ํ๋ ๋ ์๋์ผ๋ก ๋น๋๊ธฐ ์์ ์ ์์ํ ์ ์์ด. MainActor.run์ ์ฌ์ฉํด์ UI ์ ๋ฐ์ดํธ๋ ๋ฉ์ธ ์ค๋ ๋์์ ์คํ๋๋๋ก ๋ณด์ฅํ๋ ๊ฒ๋ ์ค์ํด! ๐ฏ
์ด๋ฏธ์ง ๋น๋๊ธฐ ๋ก๋ฉ
struct AsyncImageExample: View {
let imageUrl = "https://picsum.photos/300/200"
var body: some View {
VStack(spacing: 20) {
// ๊ธฐ๋ณธ AsyncImage
AsyncImage(url: URL(string: imageUrl)) { image in
image
.resizable()
.aspectRatio(contentMode: .fill)
} placeholder: {
ProgressView()
}
.frame(width: 300, height: 200)
.cornerRadius(15)
// ์ปค์คํ
๋ก๋ฉ ๋ฐ ์๋ฌ ์ฒ๋ฆฌ
AsyncImage(url: URL(string: imageUrl)) { phase in
switch phase {
case .empty:
VStack {
ProgressView()
Text("์ด๋ฏธ์ง ๋ก๋ฉ ์ค...")
.font(.caption)
}
case .success(let image):
image
.resizable()
.aspectRatio(contentMode: .fill)
.transition(.scale.combined(with: .opacity))
case .failure:
VStack {
Image(systemName: "photo")
.font(.largeTitle)
.foregroundColor(.gray)
Text("์ด๋ฏธ์ง๋ฅผ ๋ถ๋ฌ์ฌ ์ ์์ต๋๋ค")
.font(.caption)
}
@unknown default:
EmptyView()
}
}
.frame(width: 300, height: 200)
.background(Color.gray.opacity(0.1))
.cornerRadius(15)
}
}
}
AsyncImage๋ฅผ ์ฌ์ฉํ๋ฉด ๋คํธ์ํฌ ์ด๋ฏธ์ง๋ฅผ ์ ๋ง ์ฝ๊ฒ ํ์ํ ์ ์์ด. ๋ก๋ฉ ์ํ์ ์๋ฌ ์ฒ๋ฆฌ๊น์ง ๊น๋ํ๊ฒ ๊ตฌํํ ์ ์์ง! ๐ธ
๐ก ์ฑ๋ฅ ์ต์ ํ ํ:
โข ์ด๋ฏธ์ง ์บ์ฑ์ด ํ์ํ๋ค๋ฉด Kingfisher ๊ฐ์ ์๋ํํฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๊ณ ๋ คํด๋ด
โข ๋ง์ ์ด๋ฏธ์ง๋ฅผ ํ์ํ ๋๋ LazyVStack๊ณผ ํจ๊ป ์ฌ์ฉํด์ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ์ ์ต์ ํํด
โข ์ด๋ฏธ์ง ํฌ๊ธฐ๋ฅผ ์๋ฒ์์ ์ ์ ํ๊ฒ ์กฐ์ ํด์ ๋ฐ์ผ๋ฉด ๋ ์ข์
๐ ์ค์ ํ๋ก์ ํธ: ๊ฐ๋จํ ๋ฉ๋ชจ ์ฑ ๋ง๋ค๊ธฐ
์ง๊ธ๊น์ง ๋ฐฐ์ด ๋ด์ฉ์ ์ข ํฉํด์ ์ค์ ๋ก ๋์ํ๋ ๋ฉ๋ชจ ์ฑ์ ๋ง๋ค์ด๋ณด์! ์ด ์์ ์๋ CRUD ๊ธฐ๋ฅ, ์ํ ๊ด๋ฆฌ, ๋ค๋น๊ฒ์ด์ , ๋ฐ์ดํฐ ์ ์ฅ ๋ฑ์ด ๋ชจ๋ ํฌํจ๋์ด ์์ด. ๐
import SwiftUI
// MARK: - ๋ชจ๋ธ
struct Memo: Identifiable, Codable {
var id = UUID()
var title: String
var content: String
var createdAt: Date
var category: Category
enum Category: String, Codable, CaseIterable {
case personal = "๊ฐ์ธ"
case work = "์
๋ฌด"
case study = "๊ณต๋ถ"
case etc = "๊ธฐํ"
var icon: String {
switch self {
case .personal: return "person.fill"
case .work: return "briefcase.fill"
case .study: return "book.fill"
case .etc: return "star.fill"
}
}
var color: Color {
switch self {
case .personal: return .blue
case .work: return .orange
case .study: return .green
case .etc: return .purple
}
}
}
}
// MARK: - ViewModel
class MemoViewModel: ObservableObject {
@Published var memos: [Memo] = []
private let savePath = FileManager.documentsDirectory.appendingPathComponent("memos.json")
init() {
loadMemos()
}
func addMemo(_ memo: Memo) {
memos.insert(memo, at: 0)
saveMemos()
}
func updateMemo(_ memo: Memo) {
if let index = memos.firstIndex(where: { $0.id == memo.id }) {
memos[index] = memo
saveMemos()
}
}
func deleteMemo(_ memo: Memo) {
memos.removeAll { $0.id == memo.id }
saveMemos()
}
func filteredMemos(by category: Memo.Category?) -> [Memo] {
guard let category = category else { return memos }
return memos.filter { $0.category == category }
}
private func saveMemos() {
do {
let data = try JSONEncoder().encode(memos)
try data.write(to: savePath)
} catch {
print("๋ฉ๋ชจ ์ ์ฅ ์คํจ: \(error)")
}
}
private func loadMemos() {
do {
let data = try Data(contentsOf: savePath)
memos = try JSONDecoder().decode([Memo].self, from: data)
} catch {
print("๋ฉ๋ชจ ๋ก๋ ์คํจ: \(error)")
memos = []
}
}
}
// MARK: - ๋ฉ์ธ ๋ทฐ
struct MemoAppView: View {
@StateObject private var viewModel = MemoViewModel()
@State private var selectedCategory: Memo.Category?
@State private var showingAddMemo = false
var filteredMemos: [Memo] {
viewModel.filteredMemos(by: selectedCategory)
}
var body: some View {
NavigationStack {
VStack(spacing: 0) {
// ์นดํ
๊ณ ๋ฆฌ ํํฐ
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 12) {
CategoryButton(
title: "์ ์ฒด",
icon: "square.grid.2x2",
color: .gray,
isSelected: selectedCategory == nil
) {
selectedCategory = nil
}
ForEach(Memo.Category.allCases, id: \.self) { category in
CategoryButton(
title: category.rawValue,
icon: category.icon,
color: category.color,
isSelected: selectedCategory == category
) {
selectedCategory = category
}
}
}
.padding()
}
.background(Color.gray.opacity(0.05))
// ๋ฉ๋ชจ ๋ฆฌ์คํธ
if filteredMemos.isEmpty {
VStack(spacing: 20) {
Image(systemName: "note.text")
.font(.system(size: 60))
.foregroundColor(.gray)
Text("๋ฉ๋ชจ๊ฐ ์์ต๋๋ค")
.font(.headline)
.foregroundColor(.gray)
Text("+ ๋ฒํผ์ ๋๋ฌ ์ ๋ฉ๋ชจ๋ฅผ ์์ฑํ์ธ์")
.font(.caption)
.foregroundColor(.secondary)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else {
List {
ForEach(filteredMemos) { memo in
NavigationLink(destination: MemoDetailView(
viewModel: viewModel,
memo: memo
)) {
MemoRowView(memo: memo)
}
}
.onDelete { indexSet in
indexSet.forEach { index in
viewModel.deleteMemo(filteredMemos[index])
}
}
}
.listStyle(.plain)
}
}
.navigationTitle("๋ฉ๋ชจ์ฅ ๐")
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: { showingAddMemo = true }) {
Image(systemName: "plus.circle.fill")
.font(.title2)
}
}
}
.sheet(isPresented: $showingAddMemo) {
MemoEditView(viewModel: viewModel)
}
}
}
}
// MARK: - ์นดํ
๊ณ ๋ฆฌ ๋ฒํผ
struct CategoryButton: View {
let title: String
let icon: String
let color: Color
let isSelected: Bool
let action: () -> Void
var body: some View {
Button(action: action) {
HStack(spacing: 6) {
Image(systemName: icon)
Text(title)
}
.font(.subheadline)
.fontWeight(isSelected ? .bold : .regular)
.foregroundColor(isSelected ? .white : color)
.padding(.horizontal, 16)
.padding(.vertical, 8)
.background(isSelected ? color : color.opacity(0.1))
.cornerRadius(20)
}
}
}
// MARK: - ๋ฉ๋ชจ ํ ๋ทฐ
struct MemoRowView: View {
let memo: Memo
var body: some View {
VStack(alignment: .leading, spacing: 8) {
HStack {
Image(systemName: memo.category.icon)
.foregroundColor(memo.category.color)
Text(memo.title)
.font(.headline)
}
Text(memo.content)
.font(.subheadline)
.foregroundColor(.secondary)
.lineLimit(2)
Text(memo.createdAt.formatted(date: .abbreviated, time: .shortened))
.font(.caption)
.foregroundColor(.secondary)
}
.padding(.vertical, 4)
}
}
// MARK: - ๋ฉ๋ชจ ์์ธ/ํธ์ง ๋ทฐ
struct MemoDetailView: View {
@ObservedObject var viewModel: MemoViewModel
@State var memo: Memo
@State private var isEditing = false
@Environment(\.dismiss) private var dismiss
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 20) {
HStack {
Image(systemName: memo.category.icon)
.foregroundColor(memo.category.color)
Text(memo.category.rawValue)
.font(.subheadline)
.foregroundColor(memo.category.color)
Spacer()
Text(memo.createdAt.formatted(date: .abbreviated, time: .shortened))
.font(.caption)
.foregroundColor(.secondary)
}
Text(memo.title)
.font(.title)
.fontWeight(.bold)
Divider()
Text(memo.content)
.font(.body)
}
.padding()
}
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button("ํธ์ง") {
isEditing = true
}
}
}
.sheet(isPresented: $isEditing) {
MemoEditView(viewModel: viewModel, memo: memo)
}
}
}
// MARK: - ๋ฉ๋ชจ ์์ฑ/ํธ์ง ๋ทฐ
struct MemoEditView: View {
@ObservedObject var viewModel: MemoViewModel
@State var memo: Memo?
@State private var title = ""
@State private var content = ""
@State private var selectedCategory: Memo.Category = .personal
@Environment(\.dismiss) private var dismiss
var isNewMemo: Bool {
memo == nil
}
var body: some View {
NavigationStack {
Form {
Section("์ ๋ชฉ") {
TextField("๋ฉ๋ชจ ์ ๋ชฉ", text: $title)
}
Section("์นดํ
๊ณ ๋ฆฌ") {
Picker("์นดํ
๊ณ ๋ฆฌ", selection: $selectedCategory) {
ForEach(Memo.Category.allCases, id: \.self) { category in
HStack {
Image(systemName: category.icon)
Text(category.rawValue)
}
.tag(category)
}
}
.pickerStyle(.segmented)
}
Section("๋ด์ฉ") {
TextEditor(text: $content)
.frame(minHeight: 200)
}
}
.navigationTitle(isNewMemo ? "์ ๋ฉ๋ชจ" : "๋ฉ๋ชจ ํธ์ง")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button("์ทจ์") {
dismiss()
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Button("์ ์ฅ") {
saveMemo()
}
.disabled(title.isEmpty || content.isEmpty)
}
}
.onAppear {
if let memo = memo {
title = memo.title
content = memo.content
selectedCategory = memo.category
}
}
}
}
private func saveMemo() {
if let existingMemo = memo {
var updatedMemo = existingMemo
updatedMemo.title = title
updatedMemo.content = content
updatedMemo.category = selectedCategory
viewModel.updateMemo(updatedMemo)
} else {
let newMemo = Memo(
title: title,
content: content,
createdAt: Date(),
category: selectedCategory
)
viewModel.addMemo(newMemo)
}
dismiss()
}
}
// MARK: - FileManager Extension
extension FileManager {
static var documentsDirectory: URL {
FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
}
}
์ด ๋ฉ๋ชจ ์ฑ์๋ SwiftUI์ ํต์ฌ ๊ฐ๋ ๋ค์ด ๋ชจ๋ ๋ค์ด์์ด! ์ํ ๊ด๋ฆฌ(@StateObject, @ObservedObject), ๋ค๋น๊ฒ์ด์ (NavigationStack), ๋ฐ์ดํฐ ์์์ฑ(FileManager), ๋ฆฌ์คํธ ์กฐ์(CRUD), ๊ทธ๋ฆฌ๊ณ ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ์ปดํฌ๋ํธ๊น์ง! ๐
๐ฏ ์ด ํ๋ก์ ํธ์์ ๋ฐฐ์ธ ์ ์๋ ๊ฒ๋ค:
โข MVVM ์ํคํ ์ฒ ํจํด
โข Codable์ ํ์ฉํ ๋ฐ์ดํฐ ์ง๋ ฌํ
โข FileManager๋ฅผ ํตํ ๋ก์ปฌ ๋ฐ์ดํฐ ์ ์ฅ
โข ์นดํ ๊ณ ๋ฆฌ ํํฐ๋ง ๊ธฐ๋ฅ
โข Sheet๋ฅผ ํ์ฉํ ๋ชจ๋ฌ ํ๋ฉด
โข ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ์ปดํฌ๋ํธ ์ค๊ณ
๐ง SwiftUI ๊ฐ๋ฐ ํ๊ณผ ๋ฒ ์คํธ ํ๋ํฐ์ค
์ค์ ํ๋ก์ ํธ์์ SwiftUI๋ฅผ ์ฌ์ฉํ๋ฉด์ ์์๋๋ฉด ์ ๋ง ์ ์ฉํ ํ๋ค์ ๊ณต์ ํ ๊ฒ! ์ด๊ฒ๋ค๋ง ์์๋ ๊ฐ๋ฐ ์์ฐ์ฑ์ด ์์ฒญ ์ฌ๋ผ๊ฐ ๊ฑฐ์ผ. ๐ก
1. Preview๋ฅผ ์ ๊ทน ํ์ฉํ์
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
Group {
// ๋ผ์ดํธ ๋ชจ๋
ContentView()
.preferredColorScheme(.light)
.previewDisplayName("Light Mode")
// ๋คํฌ ๋ชจ๋
ContentView()
.preferredColorScheme(.dark)
.previewDisplayName("Dark Mode")
// ๋ค์ํ ๊ธฐ๊ธฐ ํฌ๊ธฐ
ContentView()
.previewDevice("iPhone SE (3rd generation)")
.previewDisplayName("iPhone SE")
ContentView()
.previewDevice("iPhone 15 Pro Max")
.previewDisplayName("iPhone 15 Pro Max")
// ๋ค์ํ Dynamic Type ํฌ๊ธฐ
ContentView()
.environment(\.sizeCategory, .extraExtraLarge)
.previewDisplayName("Large Text")
}
}
}
Preview๋ฅผ ๋ค์ํ๊ฒ ์ค์ ํ๋ฉด ์๋ฎฌ๋ ์ดํฐ๋ฅผ ์คํํ์ง ์๊ณ ๋ ์ฌ๋ฌ ํ๊ฒฝ์์ UI๋ฅผ ํ์ธํ ์ ์์ด. ๊ฐ๋ฐ ์๋๊ฐ ์ ๋ง ๋นจ๋ผ์ง์ง! โก
2. View๋ฅผ ์๊ฒ ๋๋์
โ ๏ธ ๋์ ์ - ํ๋์ ๊ฑฐ๋ํ View:
body ํ๋กํผํฐ๊ฐ 100์ค์ด ๋์ด๊ฐ๋ฉด ์ฝ๋๋ฅผ ์ฝ๊ธฐ๋ ์ด๋ ต๊ณ ์ฌ์ฌ์ฉ๋ ๋ถ๊ฐ๋ฅํด. SwiftUI๋ View๋ฅผ ์์ ๋จ์๋ก ๋๋๋ ๊ฑธ ๊ถ์ฅํด!
โ ์ข์ ์ - ์์ View๋ค๋ก ๋ถ๋ฆฌ:
๊ฐ View๋ ํ๋์ ์ฑ ์๋ง ๊ฐ์ง๋๋ก ์ค๊ณํด. ์ด๋ ๊ฒ ํ๋ฉด ์ฝ๋ ์ฌ์ฌ์ฉ์ฑ๋ ๋์์ง๊ณ , ํ ์คํธํ๊ธฐ๋ ์ฌ์์ ธ!
3. @State๋ private์ผ๋ก
// โ
์ข์ ์
struct GoodExample: View {
@State private var count = 0 // private์ผ๋ก ์ ์ธ
var body: some View {
Text("\(count)")
}
}
// โ ๋์ ์
struct BadExample: View {
@State var count = 0 // private ์์
var body: some View {
Text("\(count)")
}
}
@State๋ ํด๋น View์ ๋ด๋ถ ์ํ์ด๋ฏ๋ก ํญ์ private์ผ๋ก ์ ์ธํด์ผ ํด. ์ธ๋ถ์์ ์ ๊ทผํ ํ์๊ฐ ์๋ค๋ฉด @Binding์ ์ฌ์ฉํ๋ ๊ฒ ๋ง์!
4. ์ฑ๋ฅ ์ต์ ํ
// โ ๋นํจ์จ์ - ๋งค๋ฒ ์๋ก์ด DateFormatter ์์ฑ
struct BadDateView: View {
let date: Date
var body: some View {
Text(DateFormatter.localizedString(from: date, dateStyle: .short, timeStyle: .short))
}
}
// โ
ํจ์จ์ - DateFormatter ์ฌ์ฌ์ฉ
struct GoodDateView: View {
let date: Date
private static let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .short
formatter.timeStyle = .short
return formatter
}()
var body: some View {
Text(Self.dateFormatter.string(from: date))
}
}
// ๐ฏ ๋ ์ข์ ๋ฐฉ๋ฒ - Swift 5.5+ ์ formatted() ์ฌ์ฉ
struct BestDateView: View {
let date: Date
var body: some View {
Text(date.formatted(date: .abbreviated, time: .shortened))
}
}
๋ฌด๊ฑฐ์ด ๊ฐ์ฒด๋ ์ฌ์ฌ์ฉํ๊ณ , ๊ฐ๋ฅํ๋ฉด ์ต์ API๋ฅผ ์ฌ์ฉํ๋ ๊ฒ ์ข์. formatted()๋ ๋ด๋ถ์ ์ผ๋ก ์บ์ฑ์ ํด์ ์ฑ๋ฅ์ด ์ข์! ๐
5. ์กฐ๊ฑด๋ถ View๋ ์ ์คํ๊ฒ
// โ ํ์
์ด ๋ฌ๋ผ์ ์ปดํ์ผ ์๋ฌ ๊ฐ๋ฅ์ฑ
var body: some View {
if condition {
Text("Hello")
} else {
Image(systemName: "star")
}
}
// โ
Group์ด๋ AnyView ์ฌ์ฉ
var body: some View {
Group {
if condition {
Text("Hello")
} else {
Image(systemName: "star")
}
}
}
// ๐ฏ ๋ ์ข์ ๋ฐฉ๋ฒ - ViewBuilder ํ์ฉ
@ViewBuilder
var content: some View {
if condition {
Text("Hello")
} else {
Image(systemName: "star")
}
}
var body: some View {
content
}
๐ ์ฌ๋ฅ๋ท์์ ๋ ๋ฐฐ์ฐ๊ธฐ
SwiftUI์ iOS ๊ฐ๋ฐ์ ๋ ๊น์ด ๋ฐฐ์ฐ๊ณ ์ถ๋ค๋ฉด ์ฌ๋ฅ๋ท์ ํ์ฉํด๋ณด๋ ๊ฑด ์ด๋? ์ฌ๋ฅ๋ท(https://www.jaenung.net)์ ๋ค์ํ ๋ถ์ผ์ ์ ๋ฌธ๊ฐ๋ค์ด ์์ ์ ์ฌ๋ฅ์ ๊ณต์ ํ๋ ํ๋ซํผ์ด์ผ. ํ๋ก๊ทธ๋๋ฐ ์นดํ ๊ณ ๋ฆฌ์์ ์ค์ ๊ฒฝํ์ด ํ๋ถํ ๊ฐ๋ฐ์๋ค์ 1:1 ์ฝ์นญ์ ๋ฐ์ ์ ์์ด! ๐
ํนํ SwiftUI๋ ๊ณ์ ๋ฐ์ ํ๊ณ ์๋ ํ๋ ์์ํฌ๋ผ์, ์ค๋ฌด ๊ฒฝํ์ด ์๋ ๋ฉํ ์๊ฒ ๋ฐฐ์ฐ๋ฉด ์ต์ ํธ๋ ๋์ ์ค์ ๋ ธํ์ฐ๋ฅผ ํจ๊ป ์ป์ ์ ์์ง. ํผ์ ๊ณต๋ถํ๋ค๊ฐ ๋งํ๋ ๋ถ๋ถ์ด ์์ ๋ ์ ๋ฌธ๊ฐ์ ๋์์ ๋ฐ์ผ๋ฉด ํ์ต ์๋๊ฐ ํจ์ฌ ๋นจ๋ผ์ ธ! ๐ช
๐ฏ ์ฌ๋ฅ๋ท์์ ์ฐพ์ ์ ์๋ ๊ฒ๋ค:
โข SwiftUI ์ค์ ํ๋ก์ ํธ ๋ฉํ ๋ง
โข iOS ์ฑ ์ถ์ ์ ๋ต ์ปจ์คํ
โข ์ฝ๋ ๋ฆฌ๋ทฐ ๋ฐ ์ํคํ ์ฒ ์ค๊ณ ์กฐ์ธ
โข ํฌํธํด๋ฆฌ์ค ํ๋ก์ ํธ ๊ฐ์ด๋
โข ์ทจ์ ์ค๋น ๋ฐ ๊ธฐ์ ๋ฉด์ ๋๋น
๐ฌ ๋ง๋ฌด๋ฆฌํ๋ฉฐ
์! ์ฌ๊ธฐ๊น์ง ์ ๋ง ๊ธด ์ฌ์ ์ด์์ด. Swift 5์ ์ต์ ๋ฌธ๋ฒ๋ถํฐ SwiftUI์ ์ ์ธ์ UI ํ๋ก๊ทธ๋๋ฐ๊น์ง, ์ ๋ง ๋ง์ ๋ด์ฉ์ ๋ค๋ค์ง? ๐
SwiftUI๋ ์ฒ์์๋ ๋ฏ์ค ์ ์์ง๋ง, ์ต์ํด์ง๋ฉด ์ ๋ง ๊ฐ๋ ฅํ๊ณ ์์ฐ์ ์ธ ๋๊ตฌ์ผ. UIKit์์ ์์ญ ์ค๋ก ์์ฑํ๋ ์ฝ๋๋ฅผ ๋ช ์ค๋ก ์ค์ผ ์ ์๊ณ , ์ค์๊ฐ ํ๋ฆฌ๋ทฐ๋ก ์ฆ๊ฐ์ ์ธ ํผ๋๋ฐฑ์ ๋ฐ์ผ๋ฉด์ ๊ฐ๋ฐํ ์ ์์ด. ๊ฒ๋ค๊ฐ ์ ์ธ์ ๋ฌธ๋ฒ ๋๋ถ์ ์ฝ๋๊ฐ ์ ๋ง ์ฝ๊ธฐ ์ฝ๊ณ ์ ์ง๋ณด์ํ๊ธฐ ์ข์์ง์ง! โจ
๊ธฐ์ตํด์ผ ํ ํต์ฌ ํฌ์ธํธ๋ค์ ์ ๋ฆฌํด๋ณผ๊ฒ:
๐ SwiftUI ํต์ฌ ์์ฝ:
1. ์ ์ธ์ ํ๋ก๊ทธ๋๋ฐ - "๋ฌด์์" ๋ง๋ค์ง๋ง ์ ์ธํ๋ฉด "์ด๋ป๊ฒ"๋ ํ๋ ์์ํฌ๊ฐ ์์์ ์ฒ๋ฆฌ
2. ์ํ ๊ด๋ฆฌ - @State, @Binding, @ObservedObject, @EnvironmentObject๋ก ๋ฐ์ํ UI ๊ตฌํ
3. View ์กฐํฉ - ์์ View๋ค์ ์กฐํฉํด์ ๋ณต์กํ UI ๊ตฌ์ฑ
4. Modifier ์ฒด์ด๋ - ๋ฉ์๋ ์ฒด์ด๋์ผ๋ก View ์คํ์ผ๋ง
5. ์ ๋๋ฉ์ด์
- ๊ฐ๋จํ ์ฝ๋๋ก ๋ถ๋๋ฌ์ด ์ ๋๋ฉ์ด์
๊ตฌํ
6. ์ฌ์ฌ์ฉ์ฑ - ์ปค์คํ
View์ Modifier๋ก ์ฝ๋ ์ฌ์ฌ์ฉ
SwiftUI๋ ๊ณ์ ๋ฐ์ ํ๊ณ ์์ด. ๋งค๋ WWDC์์ ์๋ก์ด ๊ธฐ๋ฅ๋ค์ด ์ถ๊ฐ๋๊ณ , ๋ ๊ฐ๋ ฅํด์ง๊ณ ์์ง. iOS 17์์๋ ๋ ๋ง์ ๊ธฐ๋ฅ๋ค์ด ์ถ๊ฐ๋๊ณ , ์์ผ๋ก๋ ๊ณ์ ์งํํ ๊ฑฐ์ผ. ๊ทธ๋ฌ๋๊น ์ง๊ธ ๋ฐฐ์ฐ๊ธฐ ์์ํ๋ ๊ฒ ์ ๋ง ์ข์ ํ์ด๋ฐ์ด์ผ! ๐ฏ
์ฒ์์๋ ์ด๋ ต๊ฒ ๋๊ปด์ง ์ ์์ด. UIKit์ ์ต์ํ๋ค๋ฉด ์ฌ๊ณ ๋ฐฉ์์ ์์ ํ ๋ฐ๊ฟ์ผ ํ๊ฑฐ๋ . ํ์ง๋ง ํฌ๊ธฐํ์ง ๋ง๊ณ ๊ณ์ ์ฐ์ตํ๋ค ๋ณด๋ฉด ์ด๋์ SwiftUI์ ๋งค๋ ฅ์ ํน ๋น ์ ธ์์ ๊ฑฐ์ผ. ์์ ํ๋ก์ ํธ๋ถํฐ ์์ํด์ ์ ์ ๋ณต์กํ ์ฑ์ ๋ง๋ค์ด๋ณด๋ฉด์ ์ค๋ ฅ์ ํค์๋๊ฐ๋ฉด ๋ผ! ๐ช
๊ทธ๋ฆฌ๊ณ ํผ์ ๊ณต๋ถํ๋ค๊ฐ ๋งํ๋ ๋ถ๋ถ์ด ์์ผ๋ฉด ์ปค๋ฎค๋ํฐ์ ๋์์ ๋ฐ๋ ๊ฒ๋ ์ข์. Stack Overflow, Reddit์ r/SwiftUI, ๊ทธ๋ฆฌ๊ณ ํ๊ตญ์ ์ฌ๋ฌ iOS ๊ฐ๋ฐ ์ปค๋ฎค๋ํฐ๋ค์ด ์์ด. ๋ ์์ ๋งํ๋ฏ์ด ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์ ์ ๋ฌธ๊ฐ์ ๋ฉํ ๋ง์ ๋ฐ๋ ๊ฒ๋ ์ ๋ง ํจ๊ณผ์ ์ธ ํ์ต ๋ฐฉ๋ฒ์ด์ผ! ๐
์, ์ด์ ๋น์ ์ฐจ๋ก์ผ! ์ค๋ ๋ฐฐ์ด ๋ด์ฉ์ ๋ฐํ์ผ๋ก ์ง์ ์ฑ์ ๋ง๋ค์ด๋ณด์. ๊ฐ๋จํ ํ ์ผ ๊ด๋ฆฌ ์ฑ์ด๋ , ๋ ์จ ์ฑ์ด๋ , ์๋๋ฉด ์์ ํ ์๋ก์ด ์์ด๋์ด๋ ์๊ด์์ด. ์ค์ํ ๊ฑด ์ง์ ์ฝ๋๋ฅผ ์์ฑํด๋ณด๋ฉด์ ๋ฐฐ์ฐ๋ ๊ฑฐ์ผ. ์ค์ํด๋ ๊ด์ฐฎ์. ์๋ฌ ๋ฉ์์ง๋ฅผ ์ฝ๊ณ , ๊ตฌ๊ธ๋งํ๊ณ , ๋ค์ ์๋ํ๋ ๊ณผ์ ์์ ์ง์ง ์ค๋ ฅ์ด ๋์ด๋๊ฑฐ๋ ! ๐
SwiftUI๋ก ๋ฉ์ง ์ฑ์ ๋ง๋ค์ด์ App Store์ ์ถ์ํ๋ ๊ทธ๋ ์ ์์ํด๋ด. ์ ์ธ๊ณ ์ฌ๋๋ค์ด ๋น์ ์ด ๋ง๋ ์ฑ์ ์ฌ์ฉํ๋ ๊ฑฐ์ผ. ์ ๋ง ๋ฉ์ง์ง ์์? ๊ทธ ๊ฟ์ ์ด๋ฃจ๊ธฐ ์ํ ์ฒซ ๊ฑธ์์ ์ค๋ ๋ด๋๋ ์ด. ์์ผ๋ก๋ ๊ณ์ ๋ฐฐ์ฐ๊ณ , ๋ง๋ค๊ณ , ์ฑ์ฅํ์! ๐ซ
Happy Coding! ๐๐จโ๐ป๐ฉโ๐ป
๐โจ๐ฑ
SwiftUI์ ํจ๊ปํ๋ ์ฆ๊ฑฐ์ด ๊ฐ๋ฐ ์ฌ์ !
๋น์ ์ ์์ด๋์ด๋ฅผ ํ์ค๋ก ๋ง๋ค์ด๋ณด์ธ์
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.