( The whole thing about ReactiveCocoa Our project can be in https://github.com/qianhongqiang/QHQReactive download )
ReactiveCocoa I will not talk about the introduction of , Baidu .ReactiveCocoa This framework is very popular at present , But it's not popular . In the final analysis , The cost of learning is too high , Head file , You hardly know how to use it .ReactiveCocoa Internal implementations use a lot of block, stay block In the case of deep nesting , It's also hard to read the source code . I'm going to do a pull out for you , Break down the modules . Because when I started reading , I don't even know how to start . Source code analysis if there are errors , Welcome to correct .
First of all, let me show you a paragraph ReactiveCocoa Code for
```
RACSignal *signal = [RACSignal createSignal:^(id subscriber) {
[subscriber sendNext:[NSDate date]];
[subscriber sendCompleted];
return
nil;
}];
[signal subscribeNext:^(id x) {
NSLog(@
"next:%@"
, x);
} error:^(NSError *error) {
NSLog(@
"error:%@"
, error);
} completed:^{
NSLog(@
"completed"
);
}];
@interface QHQSignal ()
@property (nonatomic, copy) void (^didSubscriber)(id subscriber);
@property (nonatomic, strong) QHQSubscriber *scriber;
@end
@implementation QHQSignal
+(QHQSignal *)createSignal:(void (^)(id subscriber))didSubscriber {
QHQSignal *signal = [[self alloc] init];
signal.didSubscriber = didSubscriber;
return signal;
}
-(void)subscribeNext:(void (^)(id))nextBlock {
QHQSubscriber *scriber = [QHQSubscriber subscriberWithNextBlock:nextBlock];
self.scriber = scriber;
self.didSubscriber(self.scriber);
}
@end
@interface QHQSubscriber ()
@property (nonatomic, copy) void(^nextBlock)(id x);
@property (nonatomic, copy) void(^completionBlock)(id x);
@property (nonatomic, copy) void(^errorBlock)(id x);
@end
@implementation QHQSubscriber
+(instancetype)subscriberWithNextBlock:(void (^)(id x))nextBlock {
return [self subscriberWithNextBlock:nextBlock completionBlock:nil errorBlock:nil];
}
+(instancetype)subscriberWithNextBlock:(void (^)(id x))nextBlock completionBlock:(void (^)(id x))completionBlock errorBlock:(void (^)(id x))errorBlock {
QHQSubscriber *subscriber = [[QHQSubscriber alloc] init];
subscriber.nextBlock = nextBlock;
subscriber.completionBlock = completionBlock;
subscriber.errorBlock = errorBlock;
return subscriber;
}
-(void)sendNext:(id)next {
if (self.nextBlock) {
self.nextBlock(next);
}
}
@end
QHQSignal *demoSignal = [QHQSignal createSignal:^(id subscriber) {
[subscriber sendNext:@"1"];
}];
[demoSignal subscribeNext:^(id x) {
NSLog(@"%@",x);
}];
ReactiveCocoa Source code splitting and parsing ( One ) More articles about
- ReactiveCocoa Source code splitting and parsing ( Two )
( The whole thing about ReactiveCocoa The code engineering of can be in https://github.com/qianhongqiang/QHQReactive download ) The main signal mechanism is separated from the above . But in RA ...
- ReactiveCocoa Source code splitting and parsing ( Four )
( The whole thing about ReactiveCocoa The code engineering of can be in https://github.com/qianhongqiang/QHQReactive download ) The previous chapter briefly explained how to realize the thermal signal . But write like that , ...
- ReactiveCocoa Source code splitting and parsing ( 7、 ... and )
( The whole thing about ReactiveCocoa The code engineering of can be in https://github.com/qianhongqiang/QHQReactive download ) In this blog , I will put ReactiveCocoa Wipe in ...
- ReactiveCocoa Source code splitting and parsing ( 6、 ... and )
( The whole thing about ReactiveCocoa The code engineering of can be in https://github.com/qianhongqiang/QHQReactive download ) RAC For elegant signal binding , It can be said that I have tried my best , Not only ...
- ReactiveCocoa Source code splitting and parsing ( 5、 ... and )
( The whole thing about ReactiveCocoa The code engineering of can be in https://github.com/qianhongqiang/QHQReactive download ) I haven't written for many days , Continue today . Main explanation RAC How to UI ...
- ReactiveCocoa Source code splitting and parsing ( 3、 ... and )
( The whole thing about ReactiveCocoa The code engineering of can be in https://github.com/qianhongqiang/QHQReactive download ) This chapter mainly discusses the signal “ cold ” And “ heat ” stay RAC The world of ...
- mybatis 3.x Source code depth analysis and best practices ( The most complete and original )
mybatis 3.x Source code depth analysis and best practices 1 Environmental preparation 1.1 mybatis Introduction and framework source code learning objectives 1.2 This series of source code analysis method 1.3 Environment building 1.4 from Hello World Start 2 ...
- spring Source depth analysis — IOC And Turn on bean Loading
summary We have analyzed spring about xml Profile resolution , Assemble the analyzed information into BeanDefinition, And save it and register it with the corresponding BeanDefinitionRegistry in . thus ,Spri ...
- Spring Framework spring-web web The source code is completely parsed
Spring Framework spring-web web The source code is completely parsed spring-web yes Spring webMVC The basis of , from http.remoting.web Three parts , The core is web modular .http The module encapsulates ...
Random recommendation
- be based on redis Like function design of
Preface Like is actually a very interesting feature . There are two basic design ideas , One kind of nature is to use mysql etc. The database is directly stored on the ground , The other is to use the business features of like to throw redis( or memcache) in , And then offline brush back m ...
- watch Command real time command execution monitoring
watch command watch -d -n 1 'df; ls -FlAt /path' To use this command, you need to replace one of the /path part ,watch It's a real-time monitoring tool ,-d The parameter is highlighted Show changing ...
- Use Discuz! Built in parameter defense CC Attack and principle , modify Discuz X Turn on the anti-jamming device CC After the attack , Does not affect the search engine included method
This part of the work , It used to take too little time . Hope to have a certain effect . http://www.nigesb.com/discuz-cc-attacker-defence.html http://bbs.zb7.co ...
- UVa 10602 - Editor Nottoobad
The main idea of the topic : There's an editor , It has two commands ,“ Repeat the last word ” and “ Delete the previous letter ”, Given a series of strings , Find the minimum number of keystrokes . The first word in the title must be the first word given , So we thought about the word and the first list ...
- ecshop Detailed installation steps for
Find a... On the Internet ecshop package , Then download , decompression , After decompression ecshop It can't be used directly , You have to change the permissions of several directories to use . ecshop Put it on www Under the table of contents , In this way, you can visit directly http://localhost/e ...
- robotframework Environmental construction
Error reported at startup , The environment variables are not configured properly error : command: pybot.bat --argumentfile c:\users\keikei\appdata\local\temp\RIDEam ...
- Batch command call WINRAR Compress files
command : winrar a Parameters Compressed file Compress source files Such as compression apk file , The code is as follows echo apk Files cannot be downloaded directly , So compression apk become rar To download d: cd D:\Program Files\W ...
- my 2018:OCR、 Internships and autumn recruitment
Time really flies , It seems that I was still immersed in the success of the postgraduate entrance exam yesterday , Today is about to begin 2019 year , About to graduate with a master's degree . Old rules , On the last day of each year, I summarize this year and look forward to next year . Looking back 2018, There's so much to experience , My vision has been broadened a lot , so to speak , ...
- 6. analysis request_irq and free_irq Function to register the logout interrupt ( Detailed explanation )
The last section talked about how to implement a run interrupt , These are all done by the system , When we want to write our own interrupt handler , To execute your own code , You need to write irq_desc->action->handler, And then through request_irq ...
- GitHub Some of the tools for sorting out 【 Reprint 】
Technology sites Hacker News: Great link aggregation site for programming Programming reddit: ditto MSDN: Microsoft's official technology is concentrated in , Mainly the document class infoq: Enterprise application , Focus on software development ...