TableView reactive in swift

2

I was thinking about creating a UiTableView that follows the pattern MVVM (Model-View-ViewModel) to be able to make the data in the table refresh automatically when there is a change in these, be it a new element, an update or a deletion without having to refresh all the table.

I've been researching the subject a bit and I've found some libraries like RxSwift or Bond , but I have not found any information that will indicate that this can be done directly in a simple way without the use of external bookstores or that is contemplated in the Swift documentation.

I would appreciate if someone can give me a hand about it or guide me a bit to get it done, since I have looked a little bookstores and how to use them but it is not very intuitive.

    
asked by Joacer 22.02.2018 в 17:25
source

1 answer

3

Currently there is no option incorporated in iOS or Swift (neither Foundation nor UIKit) as such for the purposes you are looking for.

As you already commented, I would personally recommend the following:

  • RxSwift + RxCocoa
  • ReactiveKit + Bond
  • Both options have VERY good communities in Slack and Gitter where there is always someone helping.

    On the other hand, if you still want to do it on your own, I personally see maybe 2 viable options:

  • Use KVO (Key-Value Observing) and KVC (Key-Value Coding).
  • Create your own Observables (like reactive frameworks), which are nothing more than an implementation of the design pattern > Observer .
  • Personally, I would NOT like to use KVO / KVC with Swift as it would force me to create classes that inherit from NSObject and lose the flexibility to use classes and structures own of Swift.

    In summary, implementing KVO / KVC or the Observer pattern will take a long time. Personally I recommend you take that time to read about Reactive and use the available options that are now mature and stable.

        
    answered by 22.02.2018 / 18:00
    source