유튜브에서 Stanford CS193p iPhone Application Development Spring 2020을 들으며 기록했습니다.
"The Truth": 다른 곳에 데이터를 저장하거나, 다른 버전이 있는 것이 아니다
Declared: UI에 어떤 함수가 선언되어있는지 알고 아무 때나 시간에 독립적으로 호출할 수 있다. localize code. UI를 보여주기 위한 다른 코드가 흩어져 있지않고 read-only라서 예측가능하다.
imperative: 함수간 의존성이 있어서(어떤 함수가 실행되고 다른 함수가 실행) 사용자가 함수를 호출하고 UI를 아무 때나 변경하려고 하면, 관리가 어렵다
Reactive: 모델이 바뀌면 자동으로 뷰도 바뀌게 된다.
Model -> View
ViewModel은 View가 Model에 사용하기 위한 portal통로
View가 공유해야할 일이 많아서 class로 되어 있다
ViewModel은 View를 가리키는 포인터가 없다. (View는 그냥 subscribes the publication(observe), 모델까지 가지 않는다)
Model의 변화를 알아챈다(struct가 복사되거나 HTTP 요청하거나 SQL database에 접근하거나)
might "interpret": 중간에 해석할 수도 있고 안할 수도 있다
publish "something changed": 변화한 것을 보여준다
반대방향? View -> Model
Model View Intent
사용자가 화면을 카드를 클릭
stored var: 메모리에 저장됨
computed var
constant let
func
init
struct | class |
---|---|
value type | Referenc type(heap에 저장) |
copied | pointers |
Copy on write | Automatically reference counted |
Functional programming | Object-oriented programming |
No inheritance | Inheritance (single) |
"Free" init initializes ALL vars | "Free" init initializes NO vars |
Mutability must be explicitly stated(let일 때 변경 불가능) | Always mutable(힙으로 접근 가능) |
Your "go to " data structure | Used in specific circumstances |
View는 프로토콜 | MVVM모델에서 ViewModel, UIKit |
don't care 타입 -> Type parameter
예시: Array 안의 코드
strct Array<Element> {
...
func append(_ element: Element) {...}
}
var a = Array<Int>()
a.append(5)
a.append(22)
// 누군가 Array를 '사용'할 때, Element의 타입이 Int로 정해짐
(Int, Int) -> Bool // takes two Ints and returns a Bool
var foo: (Double) -> Void // foo's type: function that takes a Double, returns nothing
func doSomething(what: () -> Bool) // what's type: function, takes nothing, returns Bool
var operation: (Double) -> Double // function that takes a Double and returns a Double
func squre(operand: Double) -> Double {
return operand * operand
}
operation = squre
let result1 = operation(4) // 16
operation = sqrt // 내장함수
let result2 = operation(4) // 2
위는 View 만들기
37분 27초
아래는 Model 만들기 시작