MVVM이란?
- "코드 구성" 아키텍처 디자인 패러다임.
- "반응형" 유저-인터페이스 개념과 함께 동작.
- swiftUI가 작동하려면 준수해야 한다.
- MVC(Model View Controller)와 다른 점은 UIKit (old-style iOS)을 사용하느냐의 차이
Model
-
UI에서 독립적이다.
- UI는 SwiftUI를 import하지 않는다.
-
데이터와 로직을 캡슐화한다.
View
-
뷰는 모델을 반영한다.
-
data는 항상 Model에서 View로 향한다.
-
View는 거의 상태가 없다.
-
대부분의 상태는 Model에서 결정되기 때문이다.
-
따라서 View는 자신의 상태를 가지지 않는다.
-
-
View는 선언형 이라고 한다.
-
선언형이란?
- 무언가를 작업하기 위하여 어떻게 진행할 것인지를 나열하는 것을 뜻한다.
-
ViewModel
-
View를 Model에 Binding한다.
-
ViewModel은 Model에 변화를 준다.
-
ViewModel을 업데이트하면 바인딩으로 인해 View도 업데이트된다.
-
ViewModel은 View에 대해 아무것도 모르기 때문에 테스트가 쉽고 바인딩으로 인해 코드 양이 많이 줄어든다.
-
MVVM에서의 ViewModel은 View와 1:n관계를 이룬다.
[참고]
Lecture 2 - MVVM and the Swift Type System
CS193p - Developing Apps for iOS
The lectures for the Spring 2020 version of Stanford University's course CS193p (Developing Applications for iOS using SwiftUI) were delivered to our students in an on-line fashion due to the novel coronavirus outbreak. Stanford has made these lectur
cs193p.sites.stanford.edu
'프로그래밍 > iOS' 카테고리의 다른 글
Filling a Table with Data (0) | 2021.01.05 |
---|---|
UITableView (0) | 2021.01.05 |
Responding to Memory Warnings (0) | 2020.12.31 |
Performing One-Time Setup for Your App (0) | 2020.12.31 |
Responding to the Launch of Your App (0) | 2020.12.31 |