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 ViewModel.m ViewController.m Question / Problem 1) Well, we see the signal: When will it be complete? Only when It seems that you want it to end to 2) The advantage of 3) ... type of code
@property (get strong, nonatomic, read-only) RAC COMMAND * getItemsCommand; @ Property (strong, non-monetary, read-only) NSArray * items;
- (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; }
- (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]; }]; }
complete where I call
EndRefreshing is never executed and I do not understand for my life.
- (RACSignal *) getItems getItems instead of RAC?
RACObserve (self.viewModel, items)
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.
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.
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.
* 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
Post a Comment