RACCommand用于網(wǎng)絡(luò)請(qǐng)求
ViewModel.h文件
#import <Foundation/Foundation.h>
#import <ReactiveCocoa/ReactiveCocoa.h>
@interface ViewModel: NSObject
@property(nonatomic,strong) RACCommand *command;
@end
ViewModel.m文件
#import"ViewModel.h"
@implementationViewModel
-(instancetype)init{
if([superinit]) {
[self.command.executionSignals.switchToLatestsubscribeNext:^(idx) {
NSLog(@"收到-%@", x);
}];
[[self.command.executingskip:1]subscribeNext:^(idx) {
if([xboolValue] ==YES) {
NSLog(@"彈窗顯示正在加載網(wǎng)絡(luò)");
}else{
NSLog(@"取消彈窗顯示");
}
}];
};
returnself;
}
-(RACCommand*)command{
if(!_command){
_command= [[RACCommandalloc]initWithSignalBlock:^RACSignal*(idinput) {
NSLog(@"收到執(zhí)行命令%@",input);
return[RACSignalcreateSignal:^RACDisposable*(id subscriber) {
NSLog(@"正在加載.........");
[subscribersendNext:@"數(shù)據(jù)"];
[subscribersendCompleted];
returnnil;
}];
}];
}
return_command;
}
@end
#import
@interfaceViewModel: NSObject
@property(nonatomic,strong) RACCommand *command;
@end
#import
@interfaceViewModel :NSObject
@property(nonatomic,strong)RACCommand*command;
@end
#import
@interfaceViewModel :NSObject
@property(nonatomic,strong)RACCommand*command;
@end
#import
@interfaceViewModel :NSObject
@property(nonatomic,strong)RACCommand*command;
@end
#import
@interfaceViewModel :NSObject
@property(nonatomic,strong)RACCommand*command;
@end
#import
@interfaceViewModel :NSObject
@property(nonatomic,strong)RACCommand*command;
@end