objective c - ReactiveCocoa MVVM with UITableView -


I am using reactive cocoa and am trying to implement MVVM. There is a typical typical UITableView scenario with fresh controls to reload my data.

I left UITableDataSource / Delegate methods because they are straight forward. The code given below shows how I designed the viewold and view controller to fit together.

ViewModel.h

  @property (get strong, nonatomic, read-only) RAC COMMAND * getItemsCommand; @ Property (strong, non-monetary, read-only) NSArray * items;   

ViewModel.m

  - (instancetype) init {self = [super init]; If (! Self!) Return zero; @weakify (self); Self.getItemsCommand = [[RAC Common Alloc] initWithSignalBlock: ^ RACSignal * (id input) {return [[items get datasource) doNext: ^ (NSArray * item) {@ Strongx (self); // I actually do a little extra work like // sorting properly for the scene. Self. Item = item; }]; }]; Self return; }   

ViewController.m

  - (zero) viewDidoadload {[Super Viewedload]; [self.tableView addSubview: self.refreshControl]; RACsignal * Refresh Signals = [RACSingle Merge: @ [[Self refresh control rac_signalForControlEvents: UIControlEventValueChanged], [RACSingle Returns: Zero]]]; [RefreshScienceSubscribe: Next: ^ (id x) {[self.viewModel.getItemsCommand executed: zero]; }]; [RACObserve (self.viewModel, item) subscribeNext: ^ (NSArray * item) {[self.tableViewReloadData]; } Completed: ^ {[Self. Refresh Controller End Refreshing]; }]; }   

Question / Problem

  1. Block complete where I call EndRefreshing is never executed and I do not understand for my life.
  2. Would it be better to use a public method - (RACSignal *) getItems getItems instead of RAC?
  3. Is my use correct in scene modals (i.e. to order the array of items) to apply side effects in doNext: without any additional subscription?

    1) Well, we see the signal:

      RACObserve (self.viewModel, items)   

    When will it be complete? Only when self.viewModel or itself is distributed like any other RACObserve until those objects are all around next does not set self.items at any time.

    It seems that you want it to end to endRefreshing once getItemsCommand , and you have such implicit expectations That's because you know that this order set will be self.viewModel.items , it will be full of any kind - but it is not. To see that when the command is complete, you will have to subscribe to the returned signal of the command.

    2) The advantage of RACCommand is automatically enable / disable behavior, which you are not actually taking advantage of here, the more statutory thing will be that self .refreshControl.rac_command = self.viewModel.getItemsCommand; . They will handle end refreshing stuff for you, saving you headache from Part 1.

    3) ... type of code * injects the family of the signals in every member of the sign so if you sign a signal Subscribes twice, and it sends a next, any doNext block, it will be applied twice, a clear membership is more clear, since you want to execute it once next time No matter how many times it is subscribed.

      @weakify (self); Self.getItemsCommand = [[RAC Common Alloc] initWithSignalBlock: ^ RACSignal * (id input) {RACSignal * itemsSignal = [ItemsDataSource getItems]; [Communications subscribe next: ^ (NSERRE * item) {@ Strongx (self); // content ... self Item = item; }]; Return items}];    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -