๐ค ์ ํ ์ํ๊ณ์ UI ์ํคํ ์ฒ ์๋ฆฌ๋ฅผ ์์๋ณด์.
- SwiftUI
- UIKit
- Swift

๊ณต๋ถํ ๊ฒ ์ฐ๋๋ฏธ
๐ย ์ ํ ์ํ๊ณ์ UI ์ํคํ ์ฒ ์๋ฆฌ

์ ํ์ UI ๊ฐ๋ฐ ํ๊ฒฝ ์ Cocoa Framework ๊ณ์ธต ์์์ ๋์ํ๋ฉฐ, ๊ฐ ์ด์์ฒด์ (iOS, macOS, watchOS, tvOS)์ ๋ฐ๋ผ ๋ค๋ฅธ UI ํ๋ ์์ํฌ๋ฅผ ์ฌ์ฉํ๋ค.
๐กย Cocoa & Cocoa Touch
์ ํ์ UI๋ Cocoa ๋ฐ Cocoa Touch Framework ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๋์ํ๋ค. ์ด๋ ์ด์์ฒด์ (OS)์ ์ ํ๋ฆฌ์ผ์ด์
(Application) ์ฌ์ด์ ๋ค๋ฆฌ ์ญํ ์ ํ๋ ํต์ฌ ํ๋ ์์ํฌ์ด๋ค.
| ํ๋ ์์ํฌ | ์ฌ์ฉ OS | ์ค๋ช |
|---|---|---|
| Cocoa | macOS | macOS ์ ํ๋ฆฌ์ผ์ด์ ๊ฐ๋ฐ์ ์ํ ํ๋ ์์ํฌ (Foundation + AppKit) |
| Cocoa Touch | iOS / iPadOS / watchOS / tvOS | iOS ์ฑ ๊ฐ๋ฐ์ ์ํ ํ๋ ์์ํฌ (Foundation + UIKit) |
Cocoa: macOS ์ ํ๋ฆฌ์ผ์ด์ ๊ฐ๋ฐ์ ์ํ ๊ธฐ๋ณธ ํ๋ ์์ํฌ
โ Foundation + AppKit
Cocoa Touch: iOS ์ ํ๋ฆฌ์ผ์ด์ ๊ฐ๋ฐ์ ์ํ ํ๋ ์์ํฌ
โ Foundation + UIKit
์ฆ iOS์์ UI๋ฅผ ๊ฐ๋ฐํ ๋ UIKit๋ฅผ ์ฌ์ฉํ์ฌ UIKit๋ Cocoa Touch ์์์ ๋์ํ๋ค.
๐คย iOS์ macOS์ UI ํ๋ ์์ํฌ
์ ํ์ ๊ฐ ์ด์์ฒด์ ๋ง๋ค UI ํ๋ ์์ํฌ๋ฅผ ๋ฐ๋ก ์ ๊ณตํ์ง๋ง ์ ์ฒด์ ์ผ๋ก ๋น์ทํ ๊ตฌ์กฐ๋ฅผ ๊ฐ์ง๊ณ ์๋ค.
| ๊ธฐ๊ธฐ | UI ํ๋ ์์ํฌ |
|---|---|
| iPhone / iPad | UIKit (Cocoa Touch ๊ธฐ๋ฐ) |
| Mac | AppKit (Cocoa ๊ธฐ๋ฐ) |
| Apple Watch | WatchKit |
| Apple TV | UIKit |
| ๋ชจ๋ ํ๋ซํผ | SwiftUI (iOS, macOS, watchOS, tvOS ๊ณตํต) |
โ
ย UIKit โ iOS์์ UI๋ฅผ ๊ตฌ์ฑํ๋ ํต์ฌ ํ๋ ์์ํฌ
โ
ย AppKot โ macOS์์ UI๋ฅผ ๊ตฌ์ฑํ๋ ํต์ฌ ํ๋ ์์ํฌ
โ
ย SwiftUI โ ๋ชจ๋ ์ ํ ํ๋ซํผ์์ ๊ณตํต์ ์ผ๋ก ์ฌ์ฉํ ์ ์๋ UI ํ๋ ์์ํฌ
๐ย UIKit์ AppKit์ ์ญํ ?
UIKit์ AppKit๋ ๊ฐ๊ฐ iOS์ macOS์์ UI๋ฅผ ๊ฐ๋ฐํ๋ ์ ํต์ ์ธ ๋ฐฉ์์ด๋ค.
SwiftUI ๊ฐ ๋ฑ์ฅํ๊ธฐ ์ ๊น์ง๋ ์ด ๋๊ฐ์ ํ๋ ์์ํฌ๊ฐ ์ ํ ์ํ๊ณ์ UI๋ฅผ ๋ด๋นํ๋ค.
โ ย UIKit (iOS & iPadOS)
-
iOS์ iPadOS์์ UI๋ฅผ ๊ตฌ์ฑํ๋ ํต์ฌ ํ๋ ์์ํฌ
-
๋ทฐ ์ปจํธ๋กค๋ฌ(
UIViewController) ๊ธฐ๋ฐ์ผ๋ก ๋์ -
์คํ ๋ฆฌ๋ณด๋(Storyboard) ๋๋ ์ฝ๋ ๊ธฐ๋ฐ UI ๊ฐ๋ฐ ๊ฐ๋ฅ
-
์ฝ๋ ์์
class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let button = UIButton(type: .system) button.setTitle("ํด๋ฆญํ์ธ์", for: .normal) button.frame = CGRect(x: 50, y: 150, width: 200, height: 50) button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside) view.addSubview(button) } @objc func buttonTapped() { print("๋ฒํผ์ด ๋๋ ธ์ต๋๋ค!") } }
๐ UIViewController ๊ธฐ๋ฐ์ผ๋ก UI๋ฅผ ์ง์ ์์ฑํ๋ ๋ช
๋ นํ(Imperative UI) ๋ฐฉ์์ด๋ค.
โ ย AppKit (macOS)
-
macOS ์ ํ๋ฆฌ์ผ์ด์ ์์ UI๋ฅผ ๊ตฌ์ฑํ๋ ํ๋ ์์ํฌ
-
**์๋์ฐ ๊ธฐ๋ฐ(
NSWindow)**์ผ๋ก ๋์ -
UIKit๊ณผ๋ ๋ค๋ฅด๊ฒ macOS์ ์ ํต์ ์ธ UI ํจํด์ ๋ฐ๋ฆ
-
์ฝ๋ ์์
import Cocoa class ViewController: NSViewController { override func viewDidLoad() { super.viewDidLoad() let button = NSButton(title: "ํด๋ฆญํ์ธ์", target: self, action: #selector(buttonTapped)) button.frame = NSRect(x: 50, y: 150, width: 200, height: 50) view.addSubview(button) } @objc func buttonTapped() { print("๋ฒํผ์ด ๋๋ ธ์ต๋๋ค!") } }
๐ AppKit์์๋ NSButton ์ ์ฌ์ฉํ๊ณ macOS์ UI ๊ตฌ์กฐ์ ๋ง๊ฒ ๋์ํ๋ค.
๐ UIKit๊ณผ ๋น์ทํ์ง๋ง ์๋์ฐ ๊ธฐ๋ฐ(NSWindow)์ด๋ผ๋ ์ ์ด ๋ค๋ฅด๋ค!
๐ย ์ ํ ์ํ๊ณ ํตํฉ UI ํ๋ ์์ํฌ SwiftUI
UIKit์ AppKit๋ ์๋ก ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ ๊ฐ์ ์ ํ ์ฑ์ด๋ผ๋ ํ๋ซํผ๋ง๋ค UI๋ฅผ ๋ฐ๋ก ๊ฐ๋ฐํด์ผ ํ๋ ์์๊ฐ ๋ฐ์์ด ๋์ด ์ ํ์ ์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด SwiftUI๋ฅผ ๋์ ํ๋ค.
๐ย SwiftUI์ ํน์ง
-
๋ชจ๋ ์ ํ ํ๋ซํผ(iOS, macOS, watchOS, tvOS)์์ ์ฌ์ฉํ ์ ์๋ ๊ณตํต UI ํ๋ ์์ํฌ
-
์ ์ธํ(Declarative UI) ๋ฐฉ์ ์ฌ์ฉ
-
์ฝ๋๊ฐ ๊ฐ๊ฒฐํ๊ณ ์ ์ง๋ณด์ ์ฉ์ด
-
ํ์ง๋ง ๐กย ๋ชจ๋ UIKit ๊ธฐ๋ฅ์ ๋์ฒดํ ์ ์๋ค! (UIKit & AppKit๊ณผ ํจ๊ป ์ฌ์ฉ๋จ)
-
์ฝ๋ ์์
import SwiftUI struct ContentView: View { var body: some View { Button("ํด๋ฆญํ์ธ์") { print("๋ฒํผ์ด ๋๋ ธ์ต๋๋ค!") } .padding() } }
๐ย UIKit๊ณผ AppKit ์์ด ํ๋์ ์ฝ๋๋ก iOS/macOS UI๋ฅผ ๊ฐ๋ฐ ํ ์ ์๋ค.
๐ UI๊ฐ ์ํ(State)์ ๋ฐ๋ผ ์๋ ์ ๋ฐ์ดํธ๋๋ค.
๐ย UIKit vs AppKit vs SwiftUI ๋น๊ต
| UIKit (iOS/iPadOS) | AppKit (macOS) | SwiftUI (๊ณตํต) | |
|---|---|---|---|
| ๊ฐ๋ฐ ๋์ | iOS, iPadOS | macOS | iOS, macOS, watchOS, tvOS |
| ํ๋ ์์ํฌ ๊ธฐ๋ฐ | Cocoa Touch | Cocoa | UIKit + AppKit์ ํตํฉ |
| UI ๋ฐฉ์ | ๋ช ๋ นํ (Imperative) | ๋ช ๋ นํ (Imperative) | ์ ์ธํ (Declarative) |
| ์ง์ ๊ธฐ๊ธฐ | iPhone, iPad | Mac | iPhone, iPad, Mac, Watch, TV |
| ์ฝ๋ ์คํ์ผ | UIViewController ์ฌ์ฉ | NSViewController ์ฌ์ฉ | View ๊ตฌ์กฐ์ฒด ์ฌ์ฉ |
| ๊ธฐ์ ์ฌ์ฉ | ๋๋ถ๋ถ์ iOS ์ฑ์์ ์ฌ์ฉ | ๋๋ถ๋ถ์ macOS ์ฑ์์ ์ฌ์ฉ | ์๋ก์ด ํ๋ก์ ํธ์์ ์ ์ง์ ๋์ |
| ์ฅ์ | ๋ ์ธ๋ฐํ UI ์ปจํธ๋กค ๊ฐ๋ฅ | macOS ์ ์ฉ UI ๊ธฐ๋ฅ ์ ๊ณต | ์ฝ๋๊ฐ ๊ฐ๊ฒฐํ๊ณ ์ ์ง๋ณด์ ์ฌ์ |
| ๋จ์ | ์ฝ๋๊ฐ ๋ง์์ง ์ ์์ | UIKit๊ณผ UI ๊ตฌ์กฐ๊ฐ ๋ค๋ฆ | ์ผ๋ถ UIKit ๊ธฐ๋ฅ ๋ฏธ์ง์ |
๐คงย ํ๋์ ์ ๋ฆฌํ๊ธฐ
- Cocoa Touch (iOS)์ Cocoa (macOS)๊ฐ ์ ํ UI ํ๋ ์์ํฌ์ ๊ธฐ๋ฐ
- UIKit์ iOS & iPadOS์์ UI๋ฅผ ๋ด๋น, AppKit์ macOS์์ UI๋ฅผ ๋ด๋น
- SwiftUI๋ ๋ชจ๋ ์ ํ ๊ธฐ๊ธฐ์์ UI๋ฅผ ๊ฐ๋ฐํ ์ ์๋ ๊ณตํต ํ๋ ์์ํฌ
- UIKit๊ณผ AppKit์ด ์์ ํ ์ฌ๋ผ์ง์ง ์์ผ๋ฉฐ SwiftUI์ ํจ๊ป ์ฌ์ฉ
๋ค๋ฅธ ๊ณ์ธต์ ๋์ค์ ๊ณต๋ถํด์ผ์ง..