close


ViewModel:

跟以前的ViewModel一樣定義View需要的變數,但把class 改成struct

 


ViewController:

1.在ViewDidLoad的時候指定給viewModel(這樣第一次就會call viewModel自己的 didSet,完成One-Time Binding)

2.在viewModel didSet 裡面更新View (One-Way Binding)

3.在View的事件寫入ViewModel屬性,只要一變更ViewModel的didSet 會被call到,然後更新View (Two-Way Binding)

 

好處:

1.完全不需要BaseViewController及BaseViewModel就能達成..

2.Swift style(value types, protocol oriented programming)

3.ViewModel的屬性裡,不需再寫notifyPropertyChanged()  (之前寫的MVVMTest)

 

缺點:

1.目前序列化成Json不能使用EVReflection的第三方套件達成..

2.Value types算是新的領域,還在摸索中,不確定ViewModel太多屬性變更時..,性能上與Reference types的MVVM是否有差距!?

3.無法使用繼承,這點可用protocol的方式搭配extension 替代(目前還在摸索中)


Github: https://github.com/Bosian/SwiftValueTypesMVVM

 

 


以下是失敗的影片...

(這是失敗的影片......)

arrow
arrow
    全站熱搜

    小賢 發表在 痞客邦 留言(0) 人氣()