Stanford SWfitUI #4 강의 링크 :
► https://www.youtube.com/watch?v=oWZOFSYS5GE&list=PLpGHT1n4-mAsxuRxVPv7kj4-dQYoC3VVu&index=4
아래와 같은 코드에서 뭔지 신경쓰지 않기로한 CardContect라는 타입에 ==과 같은 연산자는 쓰고싶어. 살짝은 신경쓰고 싶어!
하는 경우에 사용하는 where Equatable ??
so is to make <CardContent> can be equatable
struct MemoryGame<CardContent> where CardContent: Equatable {
//code
if cards[chosenIndex].content == cards[potentialMatchIndex].content {
//code
}
//code
}
Model : 비즈니스 로직. 데이터에 대한 정보와 정보조작함수를 갖고있다.
ViewModel : 뷰에서 사용자 action을 감지해 모델의 로직을 호출한다. 호출된 로직에 따라 변하는 데이터값을 뷰에 다시 뿌려준다. 세세한 데이터는 뷰모델단에 담겨 모델단에서 재활용된다.
View : 사용자가 보는 화면. interact할 수 있는 척을 한다. 조작된 정보가 비춰지는 창
//ViewMode as a Gatekeeper : exposes about the Model to the View only as they need
//Swfit can detect Struct not Class
@Published private var model: MemoryGame<String> = createMemoryGame()
모델의 변경점을 observe하다 뷰에 반영시켜주겠다! 라는 으으의미....
클래스의 인스턴스 : 참조
스트럭스의 인스턴스 : 복사
???
하위 뷰와 상위 뷰를 바인딩해 어디서도 접근하고 변경하고 reflect할 수 있게 하는 기능