ν°μ€ν 리 λ·°
iOS/Design Pattern
iOS) Design pattern MVVM(1/2) - MVC, MVVM μμ보기
hyun99999 2021. 8. 24. 00:06728x90
λ°μν
π Design Pattern
- λμμΈ ν¨ν΄μ μ νκ² λλ©΄ λͺ¨λ ν΄λμ€μ μμ±μ ꡬ쑰μ μΌλ‘ μ 리κ°λ₯νλ©° ν μμ μ μνν μμ¬μν΅κ³Ό μ½λ μμ μ΄ κ°λ₯νλ€.
βοΈ MVC(Model-View-Controller)
- Model : λ°μ΄ν°μ κ΄ν λ‘μ§ λ΄λΉ(λ°μ΄ν° κ° λ³κ²½ λ° κ΄λ¦¬)
- View : μ¬μ©μμκ² λ³΄μ¬μ§λ νλ©΄ λ΄λΉ(UI)
- Controller : Model κ³Ό View μ°κ²°(Model κ°μ View μ 보μ¬μ€)
- μ€λ¦¬μ§λ MVC ν¨ν΄μ iOS κ°λ°μ μ ν©νμ§ μμ(Model,View,Controller κ° λ무 λ°μ νκ² μ°κ΄) μ νμμλ CocoaMVC ν¨ν΄μ μ μνλ€.
- Controller κ° View μ Model μ μ€μ¬μ μν μ νμ¬ View μ Model μ λ λ¦½μ± λΆμ¬.
- νμ§λ§ μ νμ CocoaMVC ν¨ν΄μμλ View μ Controller μ μν λΆλ¦¬κ° μλ²½νμ§ μλ€.
- Controller μν μ μννλ UIViewController μ Controller κ° View λ₯Ό ν¬ν¨νλ κ²μ λ¬Όλ‘ View μ life-cycle κΉμ§ κ΄λ¦¬νκΈ° λλ¬Έμ 무거μμ§κ³ , λΆλ¦¬κ° μ΄λ ΅κ³ , μ¬μ¬μ©λ μ΄λ ΅κ³ , κ°κ° ν μ€νΈνκΈ°λ μ΄λ ΅λ€.
- viewDidLoad μ κ°μ life-cycle μ΄λ²€νΈ κ΄λ¦¬, @IBAction λ±μ μ½λ°±μ²λ¦¬ λ±μΌλ‘ Massive ViewController κ° λλ€.
- κ·Έλμ μ€μ λ‘λ μλμ κ°μ κ΅¬μ‘°κ° λλ€.
μ₯λ¨μ
- μ₯μ : μμ°μ±μ΄ λλ€. μν λΆλ΄νμ¬ λΉ λ₯΄κ² ꡬν. νμ₯μ±μ΄ λλ€.
- λ¨μ : Apple's MVC μ κ²½μ° λ§μ μ½λλ€μ΄ Controller μ μ§μ€λμ΄ μ»€μ§κ² λλ€. νμ μ μ§λ³΄μκ° μ΄λ ΅λ€λ λ¬Έμ μ‘΄μ¬.
βοΈ MVVM(Model-View-ViewModel)
- MVC ν¨ν΄μ Controller κ° μ»€μ§λ λ¬Έμ λ₯Ό View Model μ λ μΌλ‘μ¨ ν΄κ²°νκ³ μ νλ€.
- Model μμ κ°μ Έμ¨ View μ μ λ°μ΄νΈν λ°μ΄ν°λ₯Ό View Model μ΄ μ²λ¦¬νκ²ν¨μΌλ‘μ¨ Controller κ° λ³΅μ‘ν΄μ§λ κ²μ μ€μ¬μ€λ€. μ¦, View Model μ presentation logic μ λ€λ£¨κ² λμ§λ§ UI λ λ€λ£¨μ§ μλλ€.
- MVVM μμ View Model μ View μ 1:n κ΄κ³λ₯Ό μ΄λ£¬λ€. View μ View Model κ°μλ λ°μ΄ν° λ°μΈλ©μ ν΅ν΄ νΉμ View μ μμ±κ³Ό View Model μμ±μ μ°κ²°ν λ€ View Model μμ±μ΄ λ³κ²½λλ©΄ μλμΌλ‘ View λ₯Ό μ λ°μ΄νΈ.
Data Binding
: View Modelκ³Ό View λ μλ‘μκ² λ°μ΄ν°μ λ³κ²½μ μλ €μ€ μ μλ λ°©λ²μ΄ νμνλ€. μ΄κ²μ΄ λ°λ‘ Data Binding μ΄λ€.
Model
- Model μ View λ View Model κ³Ό κ΄κ³μμ΄ λ 립μ μΌλ‘ ꡬμ±. μ±μ΄ μ¬μ©μμκ² λ³΄μ¬μ§λ λͺ¨μ΅μ΄λ μ 곡방μκ³Ό κ΄λ ¨μ΄ μλ€.
View
- μ¬μ©μκ° λ³Ό μ μλ μμλ€. μ΄λ²€νΈ λ°μ μ View λ View Model μ μλ¦°λ€. View λ View Model μλ§ μ κ·Ό κ°λ₯. View μ event λ₯Ό View Model μκ² μλ €μ£Όλ©΄ View Model μ΄ Model μ μ λ°μ΄νΈ μν¨λ€.
View Model
- Model κ³Ό View μ μ€κ°μ. View Model μ View μ μνλ₯Ό μ μ₯νκ³ , View μμ λ°μνλ μ‘μ μ λ°λΌ μνν μ±μ κΈ°λ₯μ μ μνλ λͺ λ Ήμ ꡬν. View Model μ View κ° μ΄λ€ λͺ¨μ΅μΈμ§ μ ν μμ§ λͺ»νλ€.
μ₯λ¨μ
- μ₯μ : ViewModel μ View μ λ 립μ μ΄λ€. μ¦ UIKit κ΄λ ¨ μ½λκ° μλ€. λ°λΌμ MVC λͺ¨λΈλ³΄λ€ μ λ ν μ€ν νκΈ°κ° μ’λ€.(View μ View Model κ°μ μμ‘΄μ±μ΄ μκΈ° λλ¬Έ)
- λ¨μ : ViewModel μ€κ³κ° λ§λ§μΉ μλ€. View μ λν μ²λ¦¬κ° 볡μ‘ν΄μ§μλ‘ ViewModel μ΄ μ€λ²μ€νμ΄ λ μ μλ€.
μΆμ²:
728x90
λ°μν
'iOS > Design Pattern' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
iOS) Design pattern MVVM(2/2) - MVVM μ€μ΅ν΄λ³΄κΈ° (0) | 2021.08.24 |
---|---|
iOS) Coordinator pattern μ μ©ν΄λ³΄μ- Advanced (7) | 2021.08.22 |
iOS) Coordinator pattern μ μ©ν΄λ³΄μ - Basic (0) | 2021.08.21 |
λκΈ
TAG
- Widget
- rxswift
- IOS
- urlsession
- Algorithm
- watchOS
- WWDC22
- Protocol
- github
- OpenSourceLibrary
- CloneCoding
- MOYA
- Firebase
- Notification
- 2022 KAKAO TECH INTERNSHIP
- YPImagePicker
- WWDC
- UserDefaults
- MVVM
- WidgetKit
- RxCocoa
- configurable widget
- Swift
- APNS
- projectsetting
- containerBackground
- SwiftUI
- async/await
- Objective-C
- μλ²ν΅μ
μ΅κ·Όμ μ¬λΌμ¨ κΈ
μ΅κ·Όμ λ¬λ¦° λκΈ
κΈ λ³΄κ΄ν¨
μΌ | μ | ν | μ | λͺ© | κΈ | ν |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
λ§ν¬
- Total
- Today
- Yesterday