├── .gitignore
├── README.md
└── basic
├── Lianxi
├── Lianxi.xcodeproj
│ ├── project.pbxproj
│ └── project.xcworkspace
│ │ └── contents.xcworkspacedata
├── Lianxi.xcworkspace
│ └── contents.xcworkspacedata
├── Lianxi
│ ├── AppDelegate.h
│ ├── AppDelegate.m
│ ├── Assets.xcassets
│ │ └── AppIcon.appiconset
│ │ │ └── Contents.json
│ ├── Base.lproj
│ │ └── LaunchScreen.storyboard
│ ├── Info.plist
│ ├── MainVC.h
│ ├── MainVC.m
│ ├── PrefixHeader.pch
│ ├── RACCommandVC.h
│ ├── RACCommandVC.m
│ ├── RACMulticastConnectionVC.h
│ ├── RACMulticastConnectionVC.m
│ ├── RACSequenceVC.h
│ ├── RACSequenceVC.m
│ ├── RACSignal1.h
│ ├── RACSignal1.m
│ ├── RACSubjectVC.h
│ ├── RACSubjectVC.m
│ ├── RACSubjectVC.xib
│ └── main.m
├── Podfile
└── Podfile.lock
├── README.md
├── Signal processing
├── Podfile
├── Podfile.lock
├── Signal processing.xcodeproj
│ ├── project.pbxproj
│ └── project.xcworkspace
│ │ └── contents.xcworkspacedata
├── Signal processing.xcworkspace
│ └── contents.xcworkspacedata
└── Signal processing
│ ├── AppDelegate.h
│ ├── AppDelegate.m
│ ├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
│ ├── Base.lproj
│ └── LaunchScreen.storyboard
│ ├── HandSignalsVC.h
│ ├── HandSignalsVC.m
│ ├── HandSignalsVC.xib
│ ├── Info.plist
│ ├── MainVC.h
│ ├── MainVC.m
│ ├── MapVC.h
│ ├── MapVC.m
│ ├── MapVC.xib
│ ├── PrefixHeader.pch
│ ├── SchedulerVC.h
│ ├── SchedulerVC.m
│ ├── SignalCombinerVC.h
│ ├── SignalCombinerVC.m
│ ├── SignalCombinerVC.xib
│ ├── SignalProcessingVC.h
│ ├── SignalProcessingVC.m
│ ├── SignalProcessingVC.xib
│ └── main.m
├── imageFile
├── 1.png
└── 2.jpg
├── the basis of RACCommand
├── Podfile
├── Podfile.lock
├── the basis of RACCommand.xcodeproj
│ ├── project.pbxproj
│ └── project.xcworkspace
│ │ └── contents.xcworkspacedata
├── the basis of RACCommand.xcworkspace
│ └── contents.xcworkspacedata
└── the basis of RACCommand
│ ├── AppDelegate.h
│ ├── AppDelegate.m
│ ├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
│ ├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
│ ├── FYNetworkManger.h
│ ├── FYNetworkManger.m
│ ├── FYRequestTool.h
│ ├── FYRequestTool.m
│ ├── Info.plist
│ ├── ViewController.h
│ ├── ViewController.m
│ ├── ViewModel.h
│ ├── ViewModel.m
│ └── main.m
├── the basis of RACSignal
├── Podfile
├── Podfile.lock
├── the basis of RACSignal.xcodeproj
│ ├── project.pbxproj
│ └── project.xcworkspace
│ │ └── contents.xcworkspacedata
├── the basis of RACSignal.xcworkspace
│ └── contents.xcworkspacedata
└── the basis of RACSignal
│ ├── AppDelegate.h
│ ├── AppDelegate.m
│ ├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
│ ├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
│ ├── Info.plist
│ ├── PersonModel.h
│ ├── PersonModel.m
│ ├── PersonViewModel.h
│ ├── PersonViewModel.m
│ ├── ViewController.h
│ ├── ViewController.m
│ └── main.m
├── the basis of RACSubject
├── Podfile
├── Podfile.lock
├── the basis of RACSubject.xcodeproj
│ ├── project.pbxproj
│ └── project.xcworkspace
│ │ └── contents.xcworkspacedata
├── the basis of RACSubject.xcworkspace
│ └── contents.xcworkspacedata
└── the basis of RACSubject
│ ├── AppDelegate.h
│ ├── AppDelegate.m
│ ├── AppleModel.h
│ ├── AppleModel.m
│ ├── AppleViewModel.h
│ ├── AppleViewModel.m
│ ├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
│ ├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
│ ├── DelegateSecondVC.h
│ ├── DelegateSecondVC.m
│ ├── DelegateSecondVC.xib
│ ├── Info.plist
│ ├── PersonModel.h
│ ├── PersonModel.m
│ ├── PersonViewModel.h
│ ├── PersonViewModel.m
│ ├── RACReplaySubjectVC.h
│ ├── RACReplaySubjectVC.m
│ ├── RACReplaySubjectVC.xib
│ ├── RACSubjectDelegateVC.h
│ ├── RACSubjectDelegateVC.m
│ ├── RACSubjectDelegateVC.xib
│ ├── RACSubjectVC.h
│ ├── RACSubjectVC.m
│ ├── RACSubjectVC.xib
│ ├── ViewController.h
│ ├── ViewController.m
│ └── main.m
└── the skills of RAC
├── MainVC.h
├── MainVC.m
├── MainVC.xib
├── Podfile
├── Podfile.lock
├── the skills of RAC.xcodeproj
├── project.pbxproj
└── project.xcworkspace
│ └── contents.xcworkspacedata
├── the skills of RAC.xcworkspace
└── contents.xcworkspacedata
└── the skills of RAC
├── AppDelegate.h
├── AppDelegate.m
├── Assets.xcassets
└── AppIcon.appiconset
│ └── Contents.json
├── Base.lproj
└── LaunchScreen.storyboard
├── DelegateVC.h
├── DelegateVC.m
├── DelegateVC.xib
├── EventVC.h
├── EventVC.m
├── EventVC.xib
├── Info.plist
├── KVOVC.h
├── KVOVC.m
├── KVOVC.xib
├── NSNotificationVC.h
├── NSNotificationVC.m
├── NSNotificationVC.xib
├── PrefixHeader.pch
├── TargetOfUISignalVC.h
├── TargetOfUISignalVC.m
├── TargetOfUISignalVC.xib
├── TimerVC.h
├── TimerVC.m
├── TimerVC.xib
└── main.m
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4 |
5 | ## Build generated
6 | build/
7 | DerivedData/
8 |
9 | ## Various settings
10 | *.pbxuser
11 | !default.pbxuser
12 | *.mode1v3
13 | !default.mode1v3
14 | *.mode2v3
15 | !default.mode2v3
16 | *.perspectivev3
17 | !default.perspectivev3
18 | xcuserdata/
19 |
20 | ## Other
21 | *.moved-aside
22 | *.xcuserstate
23 |
24 | ## Obj-C/Swift specific
25 | *.hmap
26 | *.ipa
27 | *.dSYM.zip
28 | *.dSYM
29 |
30 | # CocoaPods
31 | #
32 | # We recommend against adding the Pods directory to your .gitignore. However
33 | # you should judge for yourself, the pros and cons are mentioned at:
34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
35 | #
36 | Pods/
37 |
38 | # Carthage
39 | #
40 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
41 | # Carthage/Checkouts
42 |
43 | Carthage/Build
44 |
45 | # fastlane
46 | #
47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
48 | # screenshots whenever they are needed.
49 | # For more information about the recommended setup visit:
50 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md
51 |
52 | fastlane/report.xml
53 | fastlane/screenshots
54 |
55 | #Code Injection
56 | #
57 | # After new code Injection tools there's a generated folder /iOSInjectionProject
58 | # https://github.com/johnno1962/injectionforxcode
59 |
60 | iOSInjectionProject/
61 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // Lianxi
4 | //
5 | // Created by fy on 16/8/5.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // Lianxi
4 | //
5 | // Created by fy on 16/8/5.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | #import "MainVC.h"
12 |
13 | @interface AppDelegate ()
14 |
15 | @end
16 |
17 | @implementation AppDelegate
18 |
19 |
20 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
21 | // Override point for customization after application launch.
22 |
23 | self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
24 |
25 | MainVC * mainVC = [[MainVC alloc]init];
26 |
27 | UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:mainVC];
28 |
29 | self.window.rootViewController = nav;
30 |
31 | [self.window makeKeyAndVisible];
32 |
33 | return YES;
34 | }
35 |
36 | //-(UINavigationController*)createNavigationController:(UIViewController*)viewController withNameString:(NSString *)name{
37 | //
38 | // UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:viewController];
39 | //
40 | // nav.tabBarItem.title = name;
41 | //
42 | // return nav;
43 | //}
44 |
45 | - (void)applicationWillResignActive:(UIApplication *)application {
46 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
47 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
48 | }
49 |
50 | - (void)applicationDidEnterBackground:(UIApplication *)application {
51 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
52 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
53 | }
54 |
55 | - (void)applicationWillEnterForeground:(UIApplication *)application {
56 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
57 | }
58 |
59 | - (void)applicationDidBecomeActive:(UIApplication *)application {
60 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
61 | }
62 |
63 | - (void)applicationWillTerminate:(UIApplication *)application {
64 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
65 | }
66 |
67 | @end
68 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 |
35 | UISupportedInterfaceOrientations~ipad
36 |
37 | UIInterfaceOrientationPortrait
38 | UIInterfaceOrientationPortraitUpsideDown
39 | UIInterfaceOrientationLandscapeLeft
40 | UIInterfaceOrientationLandscapeRight
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/MainVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // MainVC.h
3 | // Lianxi
4 | //
5 | // Created by fy on 16/8/9.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface MainVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/MainVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // MainVC.m
3 | // Lianxi
4 | //
5 | // Created by fy on 16/8/9.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "MainVC.h"
10 |
11 | #import "RACSignal1.h"
12 |
13 | #import "RACSubjectVC.h"
14 |
15 | #import "RACSequenceVC.h"
16 |
17 | #import "RACMulticastConnectionVC.h"
18 |
19 | #import "RACCommandVC.h"
20 |
21 | @interface MainVC ()
22 |
23 | @end
24 |
25 | @implementation MainVC
26 |
27 | - (void)viewDidLoad {
28 | [super viewDidLoad];
29 | // Do any additional setup after loading the view.
30 |
31 | self.view.backgroundColor = [UIColor greenColor];
32 |
33 |
34 |
35 | [self setupUI];
36 | }
37 | #pragma mark - UI -
38 |
39 | -(void)setupUI{
40 |
41 | UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
42 |
43 | [self.view addSubview:tableview];
44 |
45 | [tableview mas_makeConstraints:^(MASConstraintMaker *make) {
46 |
47 | make.edges.equalTo(0);
48 |
49 | }];
50 |
51 | tableview.dataSource = self;
52 |
53 | tableview.delegate = self;
54 |
55 | [tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
56 |
57 | }
58 |
59 | #pragma mark - 数据源方法 -
60 | -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
61 |
62 | return 1;
63 |
64 | }
65 |
66 | -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
67 |
68 | return 100;
69 | }
70 |
71 | -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
72 |
73 | UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
74 |
75 | cell.selectionStyle = UITableViewCellSelectionStyleNone;
76 |
77 | switch (indexPath.row) {
78 | case 0:
79 | cell.textLabel.text = @"RACSignal";
80 | break;
81 |
82 | case 1:
83 | cell.textLabel.text = @"RACSubject";
84 | break;
85 |
86 | case 2:
87 | cell.textLabel.text = @"RACSequence";
88 | break;
89 |
90 | case 3:
91 | cell.textLabel.text = @"RACMulticastConnection";
92 | break;
93 |
94 | case 4:
95 | cell.textLabel.text = @"RACCommand";
96 | break;
97 |
98 | default:
99 | break;
100 | }
101 |
102 | return cell;
103 | }
104 |
105 | #pragma mark - 代理方法 -
106 | -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
107 |
108 |
109 | switch (indexPath.row) {
110 |
111 | case 0:
112 | {
113 | RACSignalVC * vc = [[RACSignalVC alloc]init];
114 |
115 | [self.navigationController pushViewController:vc animated:YES];
116 |
117 | break;
118 | }
119 | case 1:
120 | {
121 | RACSubjectVC * vc = [[RACSubjectVC alloc]init];
122 |
123 | [self.navigationController pushViewController:vc animated:YES];
124 |
125 | break;
126 | }
127 | case 2:
128 | {
129 | RACSequenceVC * vc = [[RACSequenceVC alloc]init];
130 |
131 | [self.navigationController pushViewController:vc animated:YES];
132 |
133 | break;
134 | }
135 |
136 | case 3:
137 | {
138 | RACMulticastConnectionVC * vc = [[RACMulticastConnectionVC alloc]init];
139 |
140 | [self.navigationController pushViewController:vc animated:YES];
141 |
142 | break;
143 | }
144 |
145 | case 4:
146 | {
147 | RACCommandVC * vc = [[RACCommandVC alloc]init];
148 |
149 | [self.navigationController pushViewController:vc animated:YES];
150 |
151 | break;
152 | }
153 |
154 | default:
155 | break;
156 | }
157 | }
158 | @end
159 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/PrefixHeader.pch:
--------------------------------------------------------------------------------
1 | //
2 | // PrefixHeader.pch
3 | // Lianxi
4 | //
5 | // Created by fy on 16/8/5.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #ifndef PrefixHeader_pch
10 | #define PrefixHeader_pch
11 |
12 | //define this constant if you want to use Masonry without the 'mas_' prefix
13 | #define MAS_SHORTHAND
14 |
15 | //define this constant if you want to enable auto-boxing for default syntax
16 | #define MAS_SHORTHAND_GLOBALS
17 |
18 | #import "Masonry.h"
19 |
20 | #import "ReactiveCocoa.h"
21 | #import "NSObject+RACKVOWrapper.h"
22 | #import "RACReturnSignal.h"
23 |
24 | #define asd 1
25 |
26 | // Include any system framework and library headers here that should be included in all compilation units.
27 | // You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.
28 |
29 | #endif /* PrefixHeader_pch */
30 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/RACCommandVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // RACCommandVC.h
3 | // Lianxi
4 | //
5 | // Created by fy on 16/8/10.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface RACCommandVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/RACCommandVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // RACCommandVC.m
3 | // Lianxi
4 | //
5 | // Created by fy on 16/8/10.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 | /*
9 | 监听事件完成或者按钮点击
10 | */
11 | #import "RACCommandVC.h"
12 |
13 | @interface RACCommandVC ()
14 |
15 | @end
16 |
17 | @implementation RACCommandVC
18 |
19 | - (void)viewDidLoad {
20 | [super viewDidLoad];
21 | // Do any additional setup after loading the view.
22 |
23 | [self createupUI];
24 | }
25 |
26 | -(void)createupUI{
27 |
28 | self.view.backgroundColor = [UIColor whiteColor];
29 |
30 | UIButton * btn = [[UIButton alloc]init];
31 |
32 | [btn setTitle:@"处理事件" forState:UIControlStateNormal];
33 |
34 | [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
35 |
36 | [btn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
37 |
38 | btn.frame = CGRectMake(100, 100, 100, 20);
39 |
40 | [self.view addSubview:btn];
41 |
42 | [btn addTarget:self action:@selector(didClickEventBtn) forControlEvents:UIControlEventTouchUpInside];
43 |
44 | UIButton * btn2 = [[UIButton alloc]init];
45 |
46 | [btn2 setTitle:@"监听事件" forState:UIControlStateNormal];
47 |
48 | [btn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
49 |
50 | [btn2 setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
51 |
52 | btn2.frame = CGRectMake(100, 200, 100, 20);
53 |
54 | [self.view addSubview:btn2];
55 |
56 | [btn2 addTarget:self action:@selector(didClickBtn) forControlEvents:UIControlEventTouchUpInside];
57 |
58 | }
59 |
60 | -(void)didClickEventBtn{
61 |
62 | RACCommand * command = [[RACCommand alloc]initWithSignalBlock:^RACSignal *(id input) {
63 |
64 | NSLog(@"input:%@",input);
65 | //这里主要体现了一个链式编程的思想
66 | return [RACSignal createSignal:^RACDisposable *(id subscriber) {
67 |
68 | [subscriber sendNext:@"数据"];
69 |
70 | return nil;
71 | }];
72 | }];
73 |
74 | [command.executionSignals subscribeNext:^(RACSignal * x) {
75 |
76 | [x subscribeNext:^(id x) {
77 | NSLog(@"%@",x);
78 | }];
79 | }];
80 |
81 | [command execute:@3];
82 |
83 |
84 | }
85 |
86 | -(void)didClickBtn{
87 |
88 | RACCommand * command = [[RACCommand alloc]initWithSignalBlock:^RACSignal *(id input) {
89 |
90 | NSLog(@"input:%@",input);
91 | //这里主要体现了一个链式编程的思想
92 | return [RACSignal createSignal:^RACDisposable *(id subscriber) {
93 |
94 | [subscriber sendNext:@"数据"];
95 |
96 | [subscriber sendCompleted];
97 |
98 | return nil;
99 | }];
100 | }];
101 | //监听事件是否完成
102 | [command.executing subscribeNext:^(id x) {
103 | if ([x boolValue]==YES) {
104 | NSLog(@"正在执行%@",x);
105 | } else {
106 | NSLog(@"执行完成/没有执行");
107 | }
108 | }];
109 |
110 | [command execute:@1];
111 | }
112 |
113 |
114 | @end
115 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/RACMulticastConnectionVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // RACMulticastConnectionVC.h
3 | // Lianxi
4 | //
5 | // Created by fy on 16/8/10.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface RACMulticastConnectionVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/RACMulticastConnectionVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // RACMulticastConnectionVC.m
3 | // Lianxi
4 | //
5 | // Created by fy on 16/8/10.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | /*
10 | 可以看到,RACMulticastConnection每次连接一次,信号发送的时候didSubscribeblock都会全部执行一遍,而不仅仅是subscriber发出的东西
11 | RACMulticastConnection主要运用的场景就是一个信号发出的时候有多个订阅者的情况
12 | */
13 | #import "RACMulticastConnectionVC.h"
14 |
15 | @interface RACMulticastConnectionVC ()
16 |
17 | @property(nonatomic,strong)RACSignal * signal;
18 |
19 | @end
20 |
21 | @implementation RACMulticastConnectionVC
22 |
23 | - (void)viewDidLoad {
24 | [super viewDidLoad];
25 | // Do any additional setup after loading the view.
26 |
27 | self.view.backgroundColor = [UIColor whiteColor];
28 |
29 | [self sendSignal];
30 |
31 | [self getSignal];
32 |
33 | [self getSecondSignal];
34 | }
35 |
36 | -(void)sendSignal{
37 |
38 | RACSignal * signal = [RACSignal createSignal:^RACDisposable *(id subscriber) {
39 |
40 | NSLog(@"发送信号");
41 |
42 | [subscriber sendNext:@"haha"];
43 |
44 | return nil;
45 | }];
46 |
47 | self.signal = signal;
48 |
49 | }
50 |
51 | -(void)getSignal{
52 |
53 | RACMulticastConnection * connection = [self.signal publish];
54 |
55 | [connection.signal subscribeNext:^(id x) {
56 | NSLog(@"1%@",x);
57 | }];
58 |
59 | [connection.signal subscribeNext:^(id x) {
60 | NSLog(@"2%@",x);
61 | }];
62 | //将信号源转化为热信号
63 | [connection connect];
64 | }
65 |
66 | -(void)getSecondSignal{
67 | RACMulticastConnection * connection = [self.signal publish];
68 |
69 | [connection.signal subscribeNext:^(id x) {
70 | NSLog(@"3%@",x);
71 | }];
72 |
73 | [connection connect];
74 | }
75 | @end
76 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/RACSequenceVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // RACSequenceVC.h
3 | // Lianxi
4 | //
5 | // Created by fy on 16/8/9.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface RACSequenceVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/RACSequenceVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // RACSequenceVC.m
3 | // Lianxi
4 | //
5 | // Created by fy on 16/8/9.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 | /*
9 | RACSequence可以更高效的遍历数组和字典
10 | */
11 | #import "RACSequenceVC.h"
12 |
13 | @interface RACSequenceVC ()
14 |
15 | @end
16 |
17 | @implementation RACSequenceVC
18 |
19 | - (void)viewDidLoad {
20 | [super viewDidLoad];
21 | // Do any additional setup after loading the view.
22 |
23 | self.view.backgroundColor = [UIColor whiteColor];
24 |
25 | NSArray * array = [self createNsarray];
26 |
27 | NSDictionary * dict = [self createDictionary];
28 |
29 | [self loadNsarray:array];
30 |
31 | [self loadDictionary:dict];
32 | }
33 | //创建
34 | -(NSArray*)createNsarray{
35 |
36 | NSArray * array = @[@1,@2,@3,@4,@5,@4,@3,@2,@1];
37 |
38 | return array;
39 | }
40 | -(NSDictionary*)createDictionary{
41 |
42 | NSDictionary * dict = @{@"key1":@1,@"key2":@2,@"key3":@3};
43 |
44 | return dict;
45 | }
46 | //读取
47 | -(void)loadNsarray:(NSArray*)array{
48 |
49 | [array.rac_sequence.signal subscribeNext:^(id x) {
50 | NSLog(@"%@",[x class]);
51 | }error:^(NSError *error) {
52 | NSLog(@"%@",error);
53 | }completed:^{
54 | NSLog(@"完成");
55 | }];
56 |
57 |
58 | }
59 |
60 | -(void)loadDictionary:(NSDictionary*)dict{
61 |
62 | [dict.rac_sequence.signal subscribeNext:^(id x) {
63 | NSLog(@"%@",x);
64 | }error:^(NSError *error) {
65 | NSLog(@"%@",error);
66 | }completed:^{
67 | NSLog(@"完成");
68 | }];
69 | }
70 | @end
71 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/RACSignal1.h:
--------------------------------------------------------------------------------
1 | //
2 | // RACSignal1.h
3 | // Lianxi
4 | //
5 | // Created by fy on 16/8/5.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface RACSignalVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/RACSignal1.m:
--------------------------------------------------------------------------------
1 | //
2 | // RACSignal1.m
3 | // Lianxi
4 | //
5 | // Created by fy on 16/8/5.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "RACSignal1.h"
10 |
11 | /*
12 | 总结
13 |
14 | .核心:
15 | .核心:信号类
16 | .信号类的作用:只要有数据改变就会把数据包装成信号传递出去
17 | .只要有数据改变就会有信号发出
18 | .数据发出,并不是信号类发出,信号类不能发送数据
19 | .使用方法:
20 | .创建信号
21 | .订阅信号
22 | .实现思路:
23 | .当一个信号被订阅,创建订阅者,并把nextBlock保存到订阅者里面。
24 | .创建的时候会返回 [RACDynamicSignal createSignal:didSubscribe];
25 | .调用RACDynamicSignal的didSubscribe
26 | .发送信号[subscriber sendNext:value];
27 | .拿到订阅者的nextBlock调用
28 | */
29 |
30 | @interface RACSignalVC ()
31 |
32 | @property(nonatomic,strong)RACSignal * signal;
33 |
34 | @end
35 |
36 | @implementation RACSignalVC
37 |
38 | - (void)viewDidLoad {
39 | [super viewDidLoad];
40 | // Do any additional setup after loading the view.
41 |
42 | [self setupUI];
43 |
44 |
45 | }
46 |
47 | -(void)setupUI{
48 |
49 | self.view.backgroundColor = [UIColor whiteColor];
50 |
51 | UIButton * btn =[[UIButton alloc]init];
52 |
53 | [self.view addSubview:btn];
54 |
55 | btn.frame = CGRectMake(200, 200, 100, 100);
56 |
57 | [btn setTitle:@"点我" forState:UIControlStateNormal];
58 |
59 | [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
60 |
61 | [btn addTarget:self action:@selector(btnDidClick) forControlEvents:UIControlEventTouchUpInside];
62 | }
63 |
64 | -(void)btnDidClick{
65 | //创建信号
66 | RACSignal * signal = [RACSignal createSignal:^RACDisposable *(id subscriber) {
67 |
68 | [subscriber sendNext:@"信号内容/signal content"];
69 |
70 | return [RACDisposable disposableWithBlock:^{
71 | NSLog(@"此时取消订阅");
72 | }];
73 | }];
74 |
75 | self.signal = signal;
76 |
77 | [self getSignal];
78 | }
79 |
80 | -(void)getSignal{
81 |
82 | //订阅信号同时返回一个取消订阅信号的对象
83 | //订阅信号
84 | RACDisposable * disposable = [self.signal subscribeNext:^(id x) {
85 | NSLog(@"%@",x);
86 | }];
87 |
88 | //完成后我们要取消订阅
89 | [disposable dispose];
90 | }
91 |
92 | -(void)dealloc{
93 |
94 | }
95 |
96 | @end
97 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/RACSubjectVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // RACSubjectVC.h
3 | // Lianxi
4 | //
5 | // Created by fy on 16/8/9.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface RACSubjectVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/RACSubjectVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // RACSubjectVC.m
3 | // Lianxi
4 | //
5 | // Created by fy on 16/8/9.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "RACSubjectVC.h"
10 |
11 | @interface RACSubjectVC ()
12 |
13 | @end
14 |
15 | @implementation RACSubjectVC
16 |
17 | - (void)viewDidLoad {
18 | [super viewDidLoad];
19 | // Do any additional setup after loading the view from its nib.
20 |
21 | //创建信号
22 | RACSubject * subject = [RACSubject subject];
23 | //订阅信号
24 | [subject subscribeNext:^(id x) {
25 | NSLog(@"此处先订阅信号,信号传值是%@",x);
26 | }];
27 | //发送信号
28 | [subject sendNext:@2];
29 | }
30 | /*
31 | 注意 RACSubject和RACReplaySubject的区别 RACSubject必须要先订阅信号之后才能发送信号, 而RACReplaySubject可以先发送信号后订阅.
32 | */
33 |
34 |
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/RACSubjectVC.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/basic/Lianxi/Lianxi/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // Lianxi
4 | //
5 | // Created by fy on 16/8/5.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/basic/Lianxi/Podfile:
--------------------------------------------------------------------------------
1 | # Uncomment this line to define a global platform for your project
2 | # platform :ios, '9.0'
3 |
4 | target 'Lianxi' do
5 | # Uncomment this line if you're using Swift or would like to use dynamic frameworks
6 | use_frameworks!
7 |
8 | # Pods for Lianxi
9 |
10 | pod 'ReactiveCocoa', '~> 4.1.0'
11 | pod 'Masonry'
12 |
13 | end
14 |
--------------------------------------------------------------------------------
/basic/Lianxi/Podfile.lock:
--------------------------------------------------------------------------------
1 | PODS:
2 | - Masonry (1.0.1)
3 | - ReactiveCocoa (4.1.0):
4 | - ReactiveCocoa/UI (= 4.1.0)
5 | - Result (~> 2.0)
6 | - ReactiveCocoa/Core (4.1.0):
7 | - ReactiveCocoa/no-arc
8 | - Result (~> 2.0)
9 | - ReactiveCocoa/no-arc (4.1.0):
10 | - Result (~> 2.0)
11 | - ReactiveCocoa/UI (4.1.0):
12 | - ReactiveCocoa/Core
13 | - Result (~> 2.0)
14 | - Result (2.1.3)
15 |
16 | DEPENDENCIES:
17 | - Masonry
18 | - ReactiveCocoa (~> 4.1.0)
19 |
20 | SPEC CHECKSUMS:
21 | Masonry: a1a931a0d08870ed8ae415a2ea5ea68ebcac77df
22 | ReactiveCocoa: d70004d7a366a7b8e87e60ce2347182c77701949
23 | Result: 18e1a7597fbcca5923c565b40a25a98afafdee02
24 |
25 | PODFILE CHECKSUM: 361e4cb8db0d7afb6fca55cf35e4832d4eae6102
26 |
27 | COCOAPODS: 1.0.1
28 |
--------------------------------------------------------------------------------
/basic/Signal processing/Podfile:
--------------------------------------------------------------------------------
1 | # Uncomment this line to define a global platform for your project
2 | platform :ios, '9.0'
3 |
4 | target 'Signal processing' do
5 | # Uncomment this line if you're using Swift or would like to use dynamic frameworks
6 | use_frameworks!
7 |
8 | # Pods for Signal processing
9 | pod ‘ReactiveCocoa’
10 | pod 'Masonry'
11 |
12 | end
13 |
--------------------------------------------------------------------------------
/basic/Signal processing/Podfile.lock:
--------------------------------------------------------------------------------
1 | PODS:
2 | - Masonry (1.0.1)
3 | - ReactiveCocoa (4.2.1):
4 | - Result (~> 2.0)
5 | - Result (2.1.3)
6 |
7 | DEPENDENCIES:
8 | - Masonry
9 | - ReactiveCocoa
10 |
11 | SPEC CHECKSUMS:
12 | Masonry: a1a931a0d08870ed8ae415a2ea5ea68ebcac77df
13 | ReactiveCocoa: 5a42745f11ea236f405bb9ce5e97c5e3b23562dd
14 | Result: 18e1a7597fbcca5923c565b40a25a98afafdee02
15 |
16 | PODFILE CHECKSUM: c296b8f90e238befebe01b4de55e3a78d56b5d93
17 |
18 | COCOAPODS: 1.0.1
19 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // Signal processing
4 | //
5 | // Created by fy on 16/8/29.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // Signal processing
4 | //
5 | // Created by fy on 16/8/29.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | #import "MainVC.h"
12 |
13 | #define screedSize [UIScreen mainScreen].bounds
14 |
15 |
16 | @interface AppDelegate ()
17 |
18 | @end
19 |
20 | @implementation AppDelegate
21 |
22 |
23 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
24 | // Override point for customization after application launch.
25 |
26 | self.window = [[UIWindow alloc]initWithFrame:screedSize];
27 |
28 | MainVC * VC = [[MainVC alloc]init];
29 |
30 | UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:VC];
31 |
32 | self.window.rootViewController = nav;
33 |
34 | [self.window makeKeyAndVisible];
35 |
36 | return YES;
37 | }
38 |
39 | - (void)applicationWillResignActive:(UIApplication *)application {
40 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
41 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
42 | }
43 |
44 | - (void)applicationDidEnterBackground:(UIApplication *)application {
45 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
46 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
47 | }
48 |
49 | - (void)applicationWillEnterForeground:(UIApplication *)application {
50 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
51 | }
52 |
53 | - (void)applicationDidBecomeActive:(UIApplication *)application {
54 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
55 | }
56 |
57 | - (void)applicationWillTerminate:(UIApplication *)application {
58 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
59 | }
60 |
61 | @end
62 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/HandSignalsVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // HandSignalsVC.h
3 | // Signal processing
4 | //
5 | // Created by fy on 16/8/30.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface HandSignalsVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/HandSignalsVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // HandSignalsVC.m
3 | // Signal processing
4 | //
5 | // Created by fy on 16/8/30.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "HandSignalsVC.h"
10 |
11 | @interface HandSignalsVC ()
12 |
13 | @property(nonatomic,strong)RACSignal * testSignal;
14 |
15 | @end
16 |
17 | @implementation HandSignalsVC
18 |
19 | #pragma mark - 生命周期 -
20 | - (void)viewDidLoad {
21 | [super viewDidLoad];
22 | // Do any additional setup after loading the view from its nib.
23 |
24 | [self createUpSignals];
25 |
26 | // [self testTheMethodOfDoNextandDoComplete];
27 |
28 | // [self testTheMethodOfInterval];
29 |
30 | [self testTheMethodOfReplay];
31 |
32 |
33 | }
34 |
35 | -(void)dealloc{
36 |
37 | NSLog(@"销毁");
38 | }
39 |
40 | #pragma mark - 创建信号 -
41 | -(void)createUpSignals{
42 |
43 | RACSignal * signal = [RACSignal createSignal:^RACDisposable *(id subscriber) {
44 |
45 | NSLog(@"1%@",[NSThread currentThread]);
46 |
47 | [subscriber sendNext:@1];
48 | // [subscriber sendNext:@1];
49 | // [subscriber sendNext:@2];
50 | // [subscriber sendNext:@1];
51 | // [subscriber sendNext:@1];
52 | // [subscriber sendNext:@3];
53 | // [subscriber sendNext:@1];
54 | // [subscriber sendNext:@1];
55 | // [subscriber sendNext:@1];
56 |
57 | [subscriber sendCompleted];
58 |
59 | return [RACDisposable disposableWithBlock:^{
60 |
61 | }];
62 | }];
63 |
64 | self.testSignal = signal;
65 |
66 | }
67 |
68 | #pragma mark - 测试方法 -
69 | -(void)testTheMethodOfDoNextandDoComplete{
70 |
71 | //doNext doComplete doError中的block会分别在对应的sendNext sendComplete sendError之前执行
72 | [[[[self.testSignal doNext:^(id x) {
73 |
74 | NSLog(@"sendNext之前会执行这个block");
75 |
76 | }] doCompleted:^{
77 |
78 | NSLog(@"sendComplete之前会执行这个block");
79 |
80 | }] doError:^(NSError *error) {
81 |
82 | NSLog(@"sendError之前会执行这个block");
83 |
84 | }] subscribeNext:^(id x) {
85 |
86 | NSLog(@"%@",x);
87 |
88 | }];
89 | }
90 |
91 | //超时自动报错
92 | -(void)testTheMethodOfTmeout{
93 |
94 | [[self.testSignal timeout:1 onScheduler:[RACScheduler mainThreadScheduler]] subscribeNext:^(id x) {
95 |
96 | NSLog(@"%@",x);
97 |
98 | } error:^(NSError *error) {
99 |
100 | //超时一秒后会自动报错
101 | NSLog(@"%@",error);
102 |
103 | }];
104 | }
105 |
106 | -(void)testTheMethodOfInterval{
107 |
108 | //每一秒执行一次,这里要加上释放信号,否则控制器推出后依旧会执行,看具体需求吧
109 | [[[RACSignal interval:1 onScheduler:[RACScheduler scheduler]]takeUntil:self.rac_willDeallocSignal ] subscribeNext:^(id x) {
110 |
111 | NSLog(@"%@",[NSDate date]);
112 |
113 | }];
114 |
115 | }
116 |
117 | //延时执行
118 | -(void)testTheMethodOfDelay{
119 |
120 | [[self.testSignal delay:2] subscribeNext:^(id x) {
121 |
122 | NSLog(@"%@",[NSDate date]);
123 |
124 | }];
125 |
126 | }
127 |
128 | //若信号发送失败信息则会重新执行
129 | -(void)testTheMethodOfRetry{
130 |
131 | [[self.testSignal retry] subscribeNext:^(id x) {
132 |
133 | NSLog(@"%@",x);
134 |
135 | } error:^(NSError *error) {
136 |
137 | NSLog(@"%@",error);
138 |
139 | }];
140 | }
141 |
142 | -(void)testTheMethodOfReplay{
143 | //当一个信号被多次订阅时,不会每次都执行一遍副作用,而是像热信号一样只执行一遍,replay内部将信号封装RACMulticastConnection的热信号
144 | RACSignal *signal = [[RACSignal createSignal:^RACDisposable *(id subscriber) {
145 |
146 | static int a = 1;
147 |
148 | [subscriber sendNext:@(a)];
149 |
150 | a ++;
151 |
152 | return nil;
153 | }] replay];
154 |
155 | [signal subscribeNext:^(id x) {
156 |
157 | NSLog(@"第一个订阅者%@",x);
158 |
159 | }];
160 |
161 | [signal subscribeNext:^(id x) {
162 |
163 | NSLog(@"第二个订阅者%@",x);
164 |
165 | }];
166 | }
167 |
168 |
169 |
170 |
171 | @end
172 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/HandSignalsVC.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/MainVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // MainVC.h
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/24.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface MainVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/MainVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // MainVC.m
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/24.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "MainVC.h"
10 |
11 | #import "MapVC.h"
12 |
13 | #import "SignalCombinerVC.h"
14 |
15 | #import "SignalProcessingVC.h"
16 |
17 | #import "HandSignalsVC.h"
18 |
19 | #import "SchedulerVC.h"
20 |
21 |
22 | @interface MainVC ()
23 |
24 | @end
25 |
26 | @implementation MainVC
27 |
28 | - (void)viewDidLoad {
29 | [super viewDidLoad];
30 | // Do any additional setup after loading the view from its nib.
31 |
32 | self.view.backgroundColor = [UIColor whiteColor];
33 |
34 | [self setupUI];
35 | }
36 |
37 |
38 | #pragma mark - UI -
39 |
40 | -(void)setupUI{
41 |
42 | UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
43 |
44 | [self.view addSubview:tableview];
45 |
46 | [tableview mas_makeConstraints:^(MASConstraintMaker *make) {
47 |
48 | make.edges.equalTo(0);
49 |
50 | }];
51 |
52 | tableview.dataSource = self;
53 |
54 | tableview.delegate = self;
55 |
56 | [tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
57 |
58 | }
59 |
60 | #pragma mark - 数据源方法 -
61 | -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
62 |
63 | return 1;
64 |
65 | }
66 |
67 | -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
68 |
69 | return 6;
70 |
71 | }
72 |
73 | -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
74 |
75 | UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
76 |
77 | cell.selectionStyle = UITableViewCellSelectionStyleNone;
78 |
79 | switch (indexPath.row) {
80 | case 0:
81 | cell.textLabel.text = @"信号的映射处理(flattenMap,Map)";
82 | break;
83 |
84 | case 1:
85 | cell.textLabel.text = @"多个信号组合处理";
86 | break;
87 |
88 | case 2:
89 | cell.textLabel.text = @"信号的筛选忽略过滤等操作";
90 | break;
91 |
92 | case 3:
93 | cell.textLabel.text = @"对信号的操作,信号发送前的一些1操作";
94 | break;
95 |
96 | case 4:
97 | cell.textLabel.text = @"调度器(多线程)";
98 | break;
99 |
100 | case 5:
101 | cell.textLabel.text = @"代替UI控件的addtarget";
102 | break;
103 |
104 | default:
105 | break;
106 | }
107 |
108 | return cell;
109 | }
110 |
111 | #pragma mark - 代理方法 -
112 | -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
113 |
114 |
115 | switch (indexPath.row) {
116 |
117 | case 0:
118 | {
119 | MapVC * vc = [[MapVC alloc]init];
120 |
121 | [self.navigationController pushViewController:vc animated:YES];
122 |
123 | break;
124 | }
125 | case 1:
126 | {
127 | SignalCombinerVC * vc = [[SignalCombinerVC alloc]init];
128 |
129 | [self.navigationController pushViewController:vc animated:YES];
130 |
131 | break;
132 | }
133 | case 2:
134 | {
135 | SignalProcessingVC * vc = [[SignalProcessingVC alloc]init];
136 |
137 | [self.navigationController pushViewController:vc animated:YES];
138 |
139 | break;
140 | }
141 |
142 | case 3:
143 | {
144 | HandSignalsVC * vc = [[HandSignalsVC alloc]init];
145 |
146 | [self.navigationController pushViewController:vc animated:YES];
147 |
148 | break;
149 | }
150 |
151 | case 4:
152 | {
153 | SchedulerVC * vc = [[SchedulerVC alloc]init];
154 |
155 | [self.navigationController pushViewController:vc animated:YES];
156 |
157 | break;
158 | }
159 | //
160 | // case 5:
161 | // {
162 | // TargetOfUISignalVC * vc = [[TargetOfUISignalVC alloc]init];
163 | //
164 | // [self.navigationController pushViewController:vc animated:YES];
165 | //
166 | // break;
167 | // }
168 |
169 | default:
170 | break;
171 | }
172 | }
173 |
174 |
175 | @end
176 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/MapVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // MapVC.h
3 | // Signal processing
4 | //
5 | // Created by fy on 16/8/29.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface MapVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/MapVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // MapVC.m
3 | // Signal processing
4 | //
5 | // Created by fy on 16/8/29.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "MapVC.h"
10 |
11 | #import "RACReturnSignal.h"
12 |
13 | @interface MapVC ()
14 |
15 | @property(nonatomic,strong)UILabel * lb_name;
16 |
17 | @property(nonatomic,strong)UILabel * lb_age;
18 |
19 | @property(nonatomic,strong)UITextField * tf_name;
20 |
21 | @property(nonatomic,strong)UITextField * tf_age;
22 |
23 | @end
24 |
25 | @implementation MapVC
26 |
27 | #pragma mark - 生命周期 -
28 |
29 | - (void)viewDidLoad {
30 | [super viewDidLoad];
31 | // Do any additional setup after loading the view from its nib.
32 |
33 | [self createupUI];
34 |
35 | //测试Map方法
36 | [self testTheMethodOfMap];
37 |
38 | //测试FlatternMap
39 | [self testTheMethodOfFlatternMap];
40 | }
41 |
42 | -(void)dealloc{
43 |
44 | NSLog(@"销毁");
45 | }
46 |
47 | #pragma mark - UI -
48 | -(void)createupUI{
49 |
50 | UITextField * tf_name = [[UITextField alloc]init];
51 |
52 | self.tf_name = tf_name;
53 |
54 | [self.view addSubview:tf_name];
55 |
56 | tf_name.borderStyle = UITextBorderStyleRoundedRect;
57 |
58 | tf_name.placeholder = @"姓名";
59 |
60 | [tf_name mas_makeConstraints:^(MASConstraintMaker *make) {
61 |
62 | make.centerX.equalTo(self.view.centerX).offset(0);
63 |
64 | make.top.equalTo(self.view.top).offset(100);
65 |
66 | make.width.equalTo(200);
67 |
68 | }];
69 |
70 | UITextField * tf_age = [[UITextField alloc]init];
71 |
72 | self.tf_age = tf_age;
73 |
74 | [self.view addSubview:tf_age];
75 |
76 | tf_age.borderStyle = UITextBorderStyleRoundedRect;
77 |
78 | tf_age.placeholder = @"年龄";
79 |
80 | [tf_age mas_makeConstraints:^(MASConstraintMaker *make) {
81 |
82 | make.centerX.equalTo(self.view.centerX).offset(0);
83 |
84 | make.top.equalTo(tf_name.bottom).offset(20);
85 |
86 | make.width.equalTo(200);
87 |
88 | }];
89 |
90 | UILabel * lb_name = [[UILabel alloc]init];
91 |
92 | self.lb_name = lb_name;
93 |
94 | [self.view addSubview:lb_name];
95 |
96 | lb_name.text = @"姓名";
97 |
98 | [lb_name mas_makeConstraints:^(MASConstraintMaker *make) {
99 |
100 | make.centerX.equalTo(self.view.centerX).offset(0);
101 |
102 | make.top.equalTo(tf_age.bottom).offset(50);
103 |
104 |
105 | }];
106 |
107 | UILabel * lb_age = [[UILabel alloc]init];
108 |
109 | self.lb_age = lb_age;
110 |
111 | [self.view addSubview:lb_age];
112 |
113 | lb_age.text = @"年龄";
114 |
115 | [lb_age mas_makeConstraints:^(MASConstraintMaker *make) {
116 |
117 | make.centerX.equalTo(self.view.centerX).offset(0);
118 |
119 | make.top.equalTo(lb_name.bottom).offset(20);
120 |
121 | }];
122 |
123 | }
124 |
125 | -(void)testTheMethodOfMap{
126 |
127 | //这里可以使用绑定写法来更快捷的达到目的,这里主要是为了体验map所以就不展示了,详情请看RACSignal的绑定
128 | //这里的映射(map)前面有讲过主要是为了对block的返回值进行处理
129 | @weakify(self);
130 | [[[self.tf_name rac_textSignal] map:^id(id value) {
131 |
132 | return [NSString stringWithFormat:@"名字是:%@",value];
133 |
134 | }] subscribeNext:^(id x) {
135 |
136 | @strongify(self);
137 | self.lb_name.text = x;
138 |
139 | }];
140 |
141 | }
142 |
143 | -(void)testTheMethodOfFlatternMap{
144 |
145 |
146 | //FlatternMap返回的是一个信号,而map返回的是信号,一般情况下我们使用的是map,只有信号中的信号我们才会使用FlatternMap
147 | //同时使用FlatternMap我们需要导入RACReturnSignal.h
148 | @weakify(self);
149 | [[[self.tf_age rac_textSignal] flattenMap:^RACStream *(id value) {
150 |
151 | return [RACReturnSignal return:[NSString stringWithFormat:@"年龄是:%@",value]];
152 |
153 | }] subscribeNext:^(id x) {
154 |
155 | @strongify(self);
156 | self.lb_age.text = x;
157 |
158 | }];
159 |
160 | }
161 |
162 |
163 | @end
164 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/MapVC.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/PrefixHeader.pch:
--------------------------------------------------------------------------------
1 | //
2 | // PrefixHeader.pch
3 | // Signal processing
4 | //
5 | // Created by fy on 16/8/29.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #ifndef PrefixHeader_pch
10 | #define PrefixHeader_pch
11 |
12 | #import "ReactiveCocoa.h"
13 |
14 | //define this constant if you want to use Masonry without the 'mas_' prefix
15 | #define MAS_SHORTHAND
16 |
17 | //define this constant if you want to enable auto-boxing for default syntax
18 | #define MAS_SHORTHAND_GLOBALS
19 |
20 | #import "Masonry.h"
21 |
22 | // Include any system framework and library headers here that should be included in all compilation units.
23 | // You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.
24 |
25 | #endif /* PrefixHeader_pch */
26 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/SchedulerVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // SchedulerVC.h
3 | // Signal processing
4 | //
5 | // Created by fy on 16/9/2.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface SchedulerVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/SchedulerVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // SchedulerVC.m
3 | // Signal processing
4 | //
5 | // Created by fy on 16/9/2.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "SchedulerVC.h"
10 |
11 | @interface SchedulerVC ()
12 |
13 | @property(nonatomic,strong)RACSignal * testSignal;
14 |
15 | @end
16 |
17 | @implementation SchedulerVC
18 |
19 | - (void)viewDidLoad {
20 | [super viewDidLoad];
21 | // Do any additional setup after loading the view.
22 |
23 | self.view.backgroundColor = [UIColor whiteColor];
24 |
25 | [self createUpSignals];
26 |
27 | [self testTheMethodOfScheduler];
28 | }
29 |
30 | #pragma mark - 创建信号 -
31 | -(void)createUpSignals{
32 |
33 | RACSignal * signal = [RACSignal createSignal:^RACDisposable *(id subscriber) {
34 |
35 | NSLog(@"sendTestSignal%@",[NSThread currentThread]);
36 |
37 | [subscriber sendNext:@1];
38 |
39 | [subscriber sendCompleted];
40 |
41 | return [RACDisposable disposableWithBlock:^{
42 |
43 | }];
44 | }];
45 |
46 | self.testSignal = signal;
47 |
48 | }
49 |
50 | #pragma mark - 测试方法
51 | -(void)testTheMethodOfScheduler{
52 |
53 | [[[RACSignal createSignal:^RACDisposable *(id subscriber) {
54 |
55 | NSLog(@"sendSignal%@",[NSThread currentThread]);
56 |
57 | [subscriber sendNext:@1];
58 |
59 | return [RACDisposable disposableWithBlock:^{
60 |
61 | }];
62 |
63 | }] subscribeOn:[RACScheduler scheduler]] subscribeNext:^(id x) {
64 |
65 | NSLog(@"receiveSignal%@",[NSThread currentThread]);
66 |
67 | }];
68 |
69 | // [[self.testSignal deliverOn:[RACScheduler scheduler]] subscribeNext:^(id x) {
70 | //
71 | // NSLog(@"receiveSignal%@",[NSThread currentThread]);
72 | //
73 | // }];
74 |
75 |
76 | }
77 |
78 | @end
79 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/SignalCombinerVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // SignalCombinerVC.h
3 | // Signal processing
4 | //
5 | // Created by fy on 16/8/29.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface SignalCombinerVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/SignalCombinerVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // SignalCombinerVC.m
3 | // Signal processing
4 | //
5 | // Created by fy on 16/8/29.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "SignalCombinerVC.h"
10 |
11 | @interface SignalCombinerVC ()
12 |
13 | @property(nonatomic,strong)UILabel * lb_name;
14 |
15 | @property(nonatomic,strong)UILabel * lb_age;
16 |
17 | @property(nonatomic,strong)UITextField * tf_name;
18 |
19 | @property(nonatomic,strong)UITextField * tf_age;
20 |
21 | @property(nonatomic,strong)RACSignal * signalA;
22 |
23 | @property(nonatomic,strong)RACSignal * signalB;
24 |
25 | @end
26 |
27 | @implementation SignalCombinerVC
28 |
29 | #pragma mark - 生命周期 -
30 | - (void)viewDidLoad {
31 |
32 | [super viewDidLoad];
33 | // Do any additional setup after loading the view from its nib.
34 |
35 | [self createupUI];
36 |
37 | [self createSignal];
38 |
39 | [self testTheMethodOfConcat];
40 |
41 | // [self testTheMethodOfThen];
42 |
43 | // [self testTheMethodOfMerge];
44 |
45 | // [self testTheMethodOfZipWith];
46 |
47 | // [self testTheMethodOfCombineLatest];
48 |
49 | // [self testOfTheMethodOfReduce];
50 | }
51 |
52 | -(void)dealloc{
53 |
54 | NSLog(@"销毁");
55 | }
56 | #pragma mark - 创建信号 -
57 | -(void)createSignal{
58 |
59 | RACSignal * signalA = [RACSignal createSignal:^RACDisposable *(id subscriber) {
60 |
61 | [subscriber sendNext:@"A"];
62 |
63 | [subscriber sendCompleted];
64 |
65 | return [RACDisposable disposableWithBlock:^{
66 |
67 | }];
68 | }];
69 |
70 | RACSignal * signalB = [RACSignal createSignal:^RACDisposable *(id subscriber) {
71 |
72 | [subscriber sendNext:@"B"];
73 |
74 | [subscriber sendCompleted];
75 |
76 | return [RACDisposable disposableWithBlock:^{
77 |
78 | }];
79 | }];
80 |
81 | self.signalA = signalA;
82 |
83 | self.signalB = signalB;
84 |
85 | }
86 |
87 | #pragma mark - 信号组合处理 -
88 |
89 | //信号的依赖
90 | -(void)testTheMethodOfConcat{
91 |
92 | //这相当于网络请求中的依赖,必须先执行完信号A才会执行信号B
93 | //经常用作一个请求执行完毕后,才会执行另一个请求
94 | //注意信号A必须要执行发送完成信号,否则信号B无法执行
95 | RACSignal * concatSignal = [self.signalA concat:self.signalB];
96 |
97 | //这里我们是对这个拼接信号进行订阅
98 | [concatSignal subscribeNext:^(id x) {
99 |
100 | NSLog(@"%@",x);
101 | }];
102 | }
103 |
104 | //信号的条件执行
105 | -(void)testTheMethodOfThen{
106 |
107 | //当地一个信号执行完才会执行then后面的信号,同时第一个信号发送出来的东西不会被订阅到
108 | @weakify(self);
109 | [[self.signalA then:^RACSignal *{
110 |
111 | @strongify(self);
112 | return self.signalB;
113 |
114 | }] subscribeNext:^(id x) {
115 |
116 | //这里只会打印出信号B的数据
117 | NSLog(@"%@",x);
118 |
119 | }];
120 |
121 | }
122 |
123 | //信号的组合
124 | -(void)testTheMethodOfMerge{
125 |
126 | RACSignal * nameSignal = [self.tf_name rac_textSignal];
127 |
128 | RACSignal * ageSignal = [self.tf_age rac_textSignal];
129 |
130 | //将两个信号组成为一个信号,若其中一个子信号发送了对象,那么组合信号也能够订阅到
131 | RACSignal * mergeSignal = [nameSignal merge:ageSignal];
132 |
133 | [mergeSignal subscribeNext:^(id x) {
134 |
135 | NSLog(@"%@",x);
136 |
137 | }];
138 |
139 | }
140 |
141 | //信号的压缩(须成对)
142 | -(void)testTheMethodOfZipWith{
143 |
144 | //信号A和B会压缩成为一个信号,当二者'同时'发送数据时,并且把两个信号的内容合并成一个元组,才会触发压缩流的next事件
145 | //注意这里的'同时'二字指的并不是时间上的同时,只要信号A发送,信号B也发送就可以了,并不需要同时,但一定要成对
146 | RACSignal * zipSignal1 = [self.signalA zipWith:self.signalB];
147 |
148 | [zipSignal1 subscribeNext:^(id x) {
149 |
150 | NSLog(@"%@",x);
151 |
152 | }];
153 |
154 | RACSignal * nameSignal = [self.tf_name rac_textSignal];
155 |
156 | RACSignal * ageSignal = [self.tf_age rac_textSignal];
157 |
158 | RACSignal * zipSignal2 = [nameSignal zipWith:ageSignal];
159 |
160 | //这里会把姓名和年龄输入框的信号包装成一个元祖,这里看起来效果会比较明显,年龄和姓名输入框若多次变动后,他们的信号呈现一个多一个少的情况下那么是无法订阅成功的
161 | //必须信号称对包装成元祖才可以
162 | [zipSignal2 subscribeNext:^(id x) {
163 |
164 | NSLog(@"%@",x);
165 | }];
166 |
167 | }
168 |
169 | //信号的压缩,每个信号只要sendNext即可
170 | -(void)testTheMethodOfCombineLatest{
171 |
172 | RACSignal * nameSignal = [self.tf_name rac_textSignal];
173 |
174 | RACSignal * ageSignal = [self.tf_age rac_textSignal];
175 |
176 | //和zip相似,只要两个信号都发送过至少一次信号就会执行,不同的是zip要求更为苛刻,需要二者信号每次执行时都必须成对,否则无法订阅成功
177 | RACSignal * combineSignal = [nameSignal combineLatestWith:ageSignal];
178 |
179 | [combineSignal subscribeNext:^(id x) {
180 |
181 | NSLog(@"%@",x);
182 | }];
183 | }
184 |
185 | //信号的聚合
186 | -(void)testOfTheMethodOfReduce{
187 |
188 | RACSignal * nameSignal = [self.tf_name rac_textSignal];
189 |
190 | RACSignal * ageSignal = [self.tf_age rac_textSignal];
191 |
192 | //先组合再聚合
193 | //reduce后的参数需要自己添加,添加以前方传来的信号的数据为准
194 | //return类似映射,可以对数据进行处理再发送给订阅者
195 | RACSignal * reduceSignal = [RACSignal combineLatest:@[nameSignal,ageSignal] reduce:^id(NSString * name,NSString * age){
196 |
197 | return [NSString stringWithFormat:@"姓名:%@,年龄:%@",name,age];
198 | }];
199 |
200 | [reduceSignal subscribeNext:^(id x) {
201 |
202 | NSLog(@"%@",x);
203 | }];
204 |
205 | }
206 |
207 | #pragma mark - UI -
208 | -(void)createupUI{
209 |
210 | UITextField * tf_name = [[UITextField alloc]init];
211 |
212 | self.tf_name = tf_name;
213 |
214 | [self.view addSubview:tf_name];
215 |
216 | tf_name.borderStyle = UITextBorderStyleRoundedRect;
217 |
218 | tf_name.placeholder = @"姓名";
219 |
220 | [tf_name mas_makeConstraints:^(MASConstraintMaker *make) {
221 |
222 | make.centerX.equalTo(self.view.centerX).offset(0);
223 |
224 | make.top.equalTo(self.view.top).offset(100);
225 |
226 | make.width.equalTo(200);
227 |
228 | }];
229 |
230 | UITextField * tf_age = [[UITextField alloc]init];
231 |
232 | self.tf_age = tf_age;
233 |
234 | [self.view addSubview:tf_age];
235 |
236 | tf_age.borderStyle = UITextBorderStyleRoundedRect;
237 |
238 | tf_age.placeholder = @"年龄";
239 |
240 | [tf_age mas_makeConstraints:^(MASConstraintMaker *make) {
241 |
242 | make.centerX.equalTo(self.view.centerX).offset(0);
243 |
244 | make.top.equalTo(tf_name.bottom).offset(20);
245 |
246 | make.width.equalTo(200);
247 |
248 | }];
249 |
250 | UILabel * lb_name = [[UILabel alloc]init];
251 |
252 | self.lb_name = lb_name;
253 |
254 | [self.view addSubview:lb_name];
255 |
256 | lb_name.text = @"姓名";
257 |
258 | [lb_name mas_makeConstraints:^(MASConstraintMaker *make) {
259 |
260 | make.centerX.equalTo(self.view.centerX).offset(0);
261 |
262 | make.top.equalTo(tf_age.bottom).offset(50);
263 |
264 |
265 | }];
266 |
267 | UILabel * lb_age = [[UILabel alloc]init];
268 |
269 | self.lb_age = lb_age;
270 |
271 | [self.view addSubview:lb_age];
272 |
273 | lb_age.text = @"年龄";
274 |
275 | [lb_age mas_makeConstraints:^(MASConstraintMaker *make) {
276 |
277 | make.centerX.equalTo(self.view.centerX).offset(0);
278 |
279 | make.top.equalTo(lb_name.bottom).offset(20);
280 |
281 | }];
282 |
283 | }
284 |
285 |
286 |
287 | @end
288 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/SignalCombinerVC.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/SignalProcessingVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // SignalProcessingVC.h
3 | // Signal processing
4 | //
5 | // Created by fy on 16/8/29.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface SignalProcessingVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/SignalProcessingVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // SignalProcessingVC.m
3 | // Signal processing
4 | //
5 | // Created by fy on 16/8/29.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "SignalProcessingVC.h"
10 |
11 | @interface SignalProcessingVC ()
12 |
13 | @property(nonatomic,strong)UITextField * tf_name;
14 |
15 | @property(nonatomic,strong)UITextField * tf_age;
16 |
17 | @property(nonatomic,strong)RACSignal * nameSignal;
18 |
19 | @property(nonatomic,strong)RACSignal * ageSignal;
20 |
21 | @property(nonatomic,strong)RACSignal * testSignal;
22 |
23 | @end
24 |
25 | @implementation SignalProcessingVC
26 |
27 | #pragma mark - 生命周期 -
28 | - (void)viewDidLoad {
29 | [super viewDidLoad];
30 | // Do any additional setup after loading the view from its nib.
31 |
32 | [self createupUI];
33 |
34 | [self createupSignal];
35 |
36 | // [self testOfTheMethodOfFilter];
37 |
38 | // [self testOfTheMethodOfIgnore];
39 |
40 | // [self testTheMethodOfDistinctUntilChanged];
41 |
42 | // [self testTheMethodOfTake];
43 |
44 | // [self testTheMethodOfTakeLast];
45 |
46 | // [self testTheMethodOfSkip];
47 |
48 | [self testTheMethodOfSwitcToLatest];
49 | }
50 |
51 | -(void)dealloc{
52 |
53 | NSLog(@"销毁");
54 | }
55 |
56 | #pragma mark - 即时搜索优化 -
57 | -(void)optimizeSearch{
58 |
59 | UITextField * tf_search = [[UITextField alloc]init];
60 |
61 | //这段代码的意思是若0.3秒内无新信号(tf无输入),并且输入框内不为空那么将会执行,这对服务器的压力减少有巨大帮助同时提高了用户体验
62 | [[[[[[tf_search.rac_textSignal throttle:0.3]distinctUntilChanged]ignore:@""] map:^id(id value) {
63 |
64 | //这里使用的是信号中的信号这个概念
65 | return [RACSignal createSignal:^RACDisposable *(id subscriber) {
66 |
67 | // network request
68 | // 这里可将请求到的信息发送出去
69 | [subscriber sendNext:value];
70 | [subscriber sendCompleted];
71 |
72 | return [RACDisposable disposableWithBlock:^{
73 |
74 | // cancel request
75 | // 这里可以将取消请求写在这里,若输入框有新输入信息那么将会发送一个新的请求,原来那个没执行完的请求将会执行这个取消请求的代码
76 |
77 | }];
78 | }];
79 | }]switchToLatest] subscribeNext:^(id x) {
80 |
81 | //这里获取信息
82 |
83 | }];
84 |
85 | }
86 |
87 | #pragma mark - 测试方法 -
88 | //过滤
89 | -(void)testOfTheMethodOfFilter{
90 |
91 | //对value进行过滤,若value的值满足条件订阅者才能够订阅到
92 | [[self.nameSignal filter:^BOOL(NSString * value) {
93 |
94 | return value.length>3;
95 |
96 | }] subscribeNext:^(id x) {
97 |
98 | NSLog(@"%@",x);
99 |
100 | }];
101 | }
102 |
103 | //忽略
104 | -(void)testOfTheMethodOfIgnore{
105 |
106 | //当信号传输的数据时ignore后的参数时,订阅者就会忽略这个信号,ignore可以嵌套,一般用来判断非空
107 | [[[self.nameSignal ignore:@"A"] ignore:@"B"] subscribeNext:^(id x) {
108 |
109 | NSLog(@"%@",x);
110 |
111 | }];
112 | }
113 |
114 | //数据不同信号才会被订阅到
115 | -(void)testTheMethodOfDistinctUntilChanged{
116 |
117 | //输入不同的字符才会获取到数值,可以用在对服务器的请求上过滤一些相同的请求,降低服务器压力
118 | //演示效果可能不太好,我重新写一组信号
119 | [[self.nameSignal distinctUntilChanged] subscribeNext:^(id x) {
120 |
121 | NSLog(@"%@",x);
122 |
123 | }];
124 |
125 | //从这里可以看出只有与上一个信号所传递的值不相同订阅者才会打印
126 | [[self.testSignal distinctUntilChanged] subscribeNext:^(id x) {
127 |
128 | NSLog(@"%@",x);
129 | }];
130 | }
131 |
132 | //获取前n个信号
133 | -(void)testTheMethodOfTake{
134 |
135 | [[self.testSignal take:3] subscribeNext:^(id x) {
136 |
137 | NSLog(@"%@",x);
138 |
139 | }];
140 | }
141 |
142 | //获取最后几次信号
143 | -(void)testTheMethodOfTakeLast{
144 |
145 | [[self.testSignal takeLast:3] subscribeNext:^(id x) {
146 |
147 | NSLog(@"%@",x);
148 |
149 | }];
150 |
151 | }
152 |
153 | //对信号的监听条件释放
154 | -(void)testTheMethodOfTakeUntil{
155 |
156 | //当对象被销毁后将不再监听
157 | //这里takeuntil后面的参数可以自己创建信号
158 | [[self.nameSignal takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
159 |
160 | NSLog(@"%@",x);
161 |
162 | }];
163 | }
164 |
165 | //跳过几个信号不接收
166 | -(void)testTheMethodOfSkip{
167 |
168 | [[self.testSignal skip:5] subscribeNext:^(id x) {
169 |
170 | NSLog(@"%@",x);
171 |
172 | }];
173 | }
174 |
175 | //获取信号中信号的最新(最后一个)信号
176 | -(void)testTheMethodOfSwitcToLatest{
177 |
178 | RACSignal * signalOfSignal = [RACSignal createSignal:^RACDisposable *(id subscriber) {
179 |
180 | [subscriber sendNext:self.testSignal];
181 |
182 | [subscriber sendCompleted];
183 |
184 | return [RACDisposable disposableWithBlock:^{
185 |
186 | }];
187 | }];
188 |
189 | [[signalOfSignal switchToLatest] subscribeNext:^(id x) {
190 |
191 | NSLog(@"%@",x);
192 | }];
193 | }
194 |
195 | #pragma mark - 创建信号 -
196 | -(void)createupSignal{
197 |
198 | RACSignal * nameSignal = [self.tf_name rac_textSignal];
199 |
200 | RACSignal * ageSignal = [self.tf_age rac_textSignal];
201 |
202 | self.nameSignal = nameSignal;
203 |
204 | self.ageSignal = ageSignal;
205 |
206 | RACSignal * signal = [RACSignal createSignal:^RACDisposable *(id subscriber) {
207 |
208 | [subscriber sendNext:@1];
209 | [subscriber sendNext:@1];
210 | [subscriber sendNext:@2];
211 | [subscriber sendNext:@1];
212 | [subscriber sendNext:@1];
213 | [subscriber sendNext:@3];
214 | [subscriber sendNext:@1];
215 | [subscriber sendNext:@1];
216 | [subscriber sendNext:@1];
217 |
218 | [subscriber sendCompleted];
219 |
220 | return [RACDisposable disposableWithBlock:^{
221 |
222 | }];
223 | }];
224 |
225 | self.testSignal = signal;
226 |
227 | }
228 |
229 | #pragma mark - UI -
230 | -(void)createupUI{
231 |
232 | UITextField * tf_name = [[UITextField alloc]init];
233 |
234 | self.tf_name = tf_name;
235 |
236 | [self.view addSubview:tf_name];
237 |
238 | tf_name.borderStyle = UITextBorderStyleRoundedRect;
239 |
240 | tf_name.placeholder = @"姓名";
241 |
242 | [tf_name mas_makeConstraints:^(MASConstraintMaker *make) {
243 |
244 | make.centerX.equalTo(self.view.centerX).offset(0);
245 |
246 | make.top.equalTo(self.view.top).offset(100);
247 |
248 | make.width.equalTo(200);
249 |
250 | }];
251 |
252 | UITextField * tf_age = [[UITextField alloc]init];
253 |
254 | self.tf_age = tf_age;
255 |
256 | [self.view addSubview:tf_age];
257 |
258 | tf_age.borderStyle = UITextBorderStyleRoundedRect;
259 |
260 | tf_age.placeholder = @"年龄";
261 |
262 | [tf_age mas_makeConstraints:^(MASConstraintMaker *make) {
263 |
264 | make.centerX.equalTo(self.view.centerX).offset(0);
265 |
266 | make.top.equalTo(tf_name.bottom).offset(20);
267 |
268 | make.width.equalTo(200);
269 |
270 | }];
271 |
272 | }
273 |
274 | @end
275 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/SignalProcessingVC.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/basic/Signal processing/Signal processing/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // Signal processing
4 | //
5 | // Created by fy on 16/8/29.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/basic/imageFile/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/harofan/StudyForRAC/c495d31f64beed5ce01942b0355f03f273dfc38d/basic/imageFile/1.png
--------------------------------------------------------------------------------
/basic/imageFile/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/harofan/StudyForRAC/c495d31f64beed5ce01942b0355f03f273dfc38d/basic/imageFile/2.jpg
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/Podfile:
--------------------------------------------------------------------------------
1 | # Uncomment this line to define a global platform for your project
2 | platform :ios, '9.0'
3 |
4 | target 'the basis of RACCommand' do
5 | # Uncomment this line if you're using Swift or would like to use dynamic frameworks
6 | use_frameworks!
7 |
8 | # Pods for the basis of RACCommand
9 |
10 | pod 'AFNetworking'
11 | pod 'ReactiveCocoa'
12 |
13 | end
14 |
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/Podfile.lock:
--------------------------------------------------------------------------------
1 | PODS:
2 | - AFNetworking (3.1.0):
3 | - AFNetworking/NSURLSession (= 3.1.0)
4 | - AFNetworking/Reachability (= 3.1.0)
5 | - AFNetworking/Security (= 3.1.0)
6 | - AFNetworking/Serialization (= 3.1.0)
7 | - AFNetworking/UIKit (= 3.1.0)
8 | - AFNetworking/NSURLSession (3.1.0):
9 | - AFNetworking/Reachability
10 | - AFNetworking/Security
11 | - AFNetworking/Serialization
12 | - AFNetworking/Reachability (3.1.0)
13 | - AFNetworking/Security (3.1.0)
14 | - AFNetworking/Serialization (3.1.0)
15 | - AFNetworking/UIKit (3.1.0):
16 | - AFNetworking/NSURLSession
17 | - ReactiveCocoa (4.2.1):
18 | - Result (~> 2.0)
19 | - Result (2.1.3)
20 |
21 | DEPENDENCIES:
22 | - AFNetworking
23 | - ReactiveCocoa
24 |
25 | SPEC CHECKSUMS:
26 | AFNetworking: 5e0e199f73d8626b11e79750991f5d173d1f8b67
27 | ReactiveCocoa: 5a42745f11ea236f405bb9ce5e97c5e3b23562dd
28 | Result: 18e1a7597fbcca5923c565b40a25a98afafdee02
29 |
30 | PODFILE CHECKSUM: 5251c3f2b0f2bb02a22115ce44a432fa4dd75169
31 |
32 | COCOAPODS: 1.0.1
33 |
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/the basis of RACCommand.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/the basis of RACCommand.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/the basis of RACCommand/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // the basis of RACCommand
4 | //
5 | // Created by fy on 16/8/22.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/the basis of RACCommand/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // the basis of RACCommand
4 | //
5 | // Created by fy on 16/8/22.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | @interface AppDelegate ()
12 |
13 | @end
14 |
15 | @implementation AppDelegate
16 |
17 |
18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19 | // Override point for customization after application launch.
20 | return YES;
21 | }
22 |
23 | - (void)applicationWillResignActive:(UIApplication *)application {
24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
26 | }
27 |
28 | - (void)applicationDidEnterBackground:(UIApplication *)application {
29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
31 | }
32 |
33 | - (void)applicationWillEnterForeground:(UIApplication *)application {
34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
35 | }
36 |
37 | - (void)applicationDidBecomeActive:(UIApplication *)application {
38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
39 | }
40 |
41 | - (void)applicationWillTerminate:(UIApplication *)application {
42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
43 | }
44 |
45 | @end
46 |
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/the basis of RACCommand/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/the basis of RACCommand/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/the basis of RACCommand/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/the basis of RACCommand/FYNetworkManger.h:
--------------------------------------------------------------------------------
1 | //
2 | // FYNetworkManger.h
3 | // FYBILIBILI
4 | //
5 | // Created by fy on 16/8/4.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface FYNetworkManger : AFHTTPSessionManager
12 | //获取单例
13 | +(instancetype)shareManager;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/the basis of RACCommand/FYNetworkManger.m:
--------------------------------------------------------------------------------
1 | //
2 | // FYNetworkManger.m
3 | // FYBILIBILI
4 | //
5 | // Created by fy on 16/8/4.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "FYNetworkManger.h"
10 |
11 | @implementation FYNetworkManger
12 |
13 | //三种解析json格式
14 | - (instancetype)init
15 | {
16 | self = [super init];
17 | if (!self) return nil;
18 | self.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/plain",@"text/html", nil];
19 | return self;
20 | }
21 |
22 | +(instancetype)shareManager{
23 |
24 | static FYNetworkManger * _instance;
25 |
26 | static dispatch_once_t onceToken;
27 |
28 | dispatch_once(&onceToken, ^{
29 |
30 | _instance = [[self alloc]init];
31 |
32 | });
33 |
34 | return _instance;
35 | }
36 |
37 | @end
38 |
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/the basis of RACCommand/FYRequestTool.h:
--------------------------------------------------------------------------------
1 | //
2 | // FYRequestTool.h
3 | // FYBILIBILI
4 | //
5 | // Created by fy on 16/8/4.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #import "FYNetworkManger.h"
12 |
13 | @interface FYRequestTool : NSObject
14 |
15 | //中间必须有值
16 | NS_ASSUME_NONNULL_BEGIN
17 | + (nullable NSURLSessionDataTask *)GET:(NSString *)URLString
18 | parameters:(nullable id)parameters
19 | progress:(nullable void (^)(NSProgress *downloadProgress))downloadProgress
20 | success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
21 | failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;
22 |
23 |
24 | + (nullable NSURLSessionDataTask *)POST:(NSString *)URLString
25 | parameters:(nullable id)parameters
26 | progress:(nullable void (^)(NSProgress *uploadProgress))uploadProgress
27 | success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
28 | failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;
29 |
30 | + (void)cancel;
31 |
32 | @end
33 | NS_ASSUME_NONNULL_END
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/the basis of RACCommand/FYRequestTool.m:
--------------------------------------------------------------------------------
1 | //
2 | // FYRequestTool.m
3 | // FYBILIBILI
4 | //
5 | // Created by fy on 16/8/4.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "FYRequestTool.h"
10 |
11 | @implementation FYRequestTool
12 |
13 | +(NSURLSessionDataTask *)GET:(NSString *)URLString
14 | parameters:(id)parameters
15 | progress:(void (^)(NSProgress * _Nonnull))downloadProgress
16 | success:(void (^)(NSURLSessionDataTask * _Nonnull, id _Nullable))success
17 | failure:(void (^)(NSURLSessionDataTask * _Nullable, NSError * _Nonnull))failure{
18 |
19 | FYNetworkManger * mgr = [FYNetworkManger shareManager];
20 |
21 | NSURLSessionDataTask * DataTask =[mgr GET:URLString parameters:parameters progress:downloadProgress success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
22 |
23 | success(task,responseObject);
24 |
25 | } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
26 |
27 | failure(task,error);
28 | }];
29 |
30 | return DataTask;
31 | }
32 |
33 | +(NSURLSessionDataTask *)POST:(NSString *)URLString
34 | parameters:(id)parameters
35 | progress:(void (^)(NSProgress * _Nonnull))uploadProgress
36 | success:(void (^)(NSURLSessionDataTask * _Nonnull, id _Nullable))success
37 | failure:(void (^)(NSURLSessionDataTask * _Nullable, NSError * _Nonnull))failure{
38 |
39 | FYNetworkManger * mgr = [FYNetworkManger shareManager];
40 |
41 | NSURLSessionDataTask * DataTask =[mgr POST:URLString parameters:parameters progress:uploadProgress success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
42 |
43 | success(task,responseObject);
44 |
45 | } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
46 |
47 | failure(task,error);
48 | }];
49 |
50 | return DataTask;
51 | }
52 |
53 | +(void)cancel{
54 |
55 | // 取消网络请求
56 | [[FYNetworkManger shareManager].operationQueue cancelAllOperations];
57 |
58 | // 取消任务中的所有网络请求
59 | // [[FYNetworkManger shareManager].tasks makeObjectsPerformSelector:@selector(cancel)];
60 |
61 | // 杀死Session
62 | // [[FYNetworkManger shareManager] invalidateSessionCancelingTasks:YES];
63 |
64 | }
65 |
66 | @end
67 |
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/the basis of RACCommand/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | NSAppTransportSecurity
6 |
7 | NSAllowsArbitraryLoads
8 |
9 |
10 | CFBundleDevelopmentRegion
11 | en
12 | CFBundleExecutable
13 | $(EXECUTABLE_NAME)
14 | CFBundleIdentifier
15 | $(PRODUCT_BUNDLE_IDENTIFIER)
16 | CFBundleInfoDictionaryVersion
17 | 6.0
18 | CFBundleName
19 | $(PRODUCT_NAME)
20 | CFBundlePackageType
21 | APPL
22 | CFBundleShortVersionString
23 | 1.0
24 | CFBundleSignature
25 | ????
26 | CFBundleVersion
27 | 1
28 | LSRequiresIPhoneOS
29 |
30 | UILaunchStoryboardName
31 | LaunchScreen
32 | UIMainStoryboardFile
33 | Main
34 | UIRequiredDeviceCapabilities
35 |
36 | armv7
37 |
38 | UISupportedInterfaceOrientations
39 |
40 | UIInterfaceOrientationPortrait
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 | UISupportedInterfaceOrientations~ipad
45 |
46 | UIInterfaceOrientationPortrait
47 | UIInterfaceOrientationPortraitUpsideDown
48 | UIInterfaceOrientationLandscapeLeft
49 | UIInterfaceOrientationLandscapeRight
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/the basis of RACCommand/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // the basis of RACCommand
4 | //
5 | // Created by fy on 16/8/22.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UIViewController
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/the basis of RACCommand/ViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // the basis of RACCommand
4 | //
5 | // Created by fy on 16/8/22.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "ViewController.h"
10 |
11 | #import "ViewModel.h"
12 |
13 | @interface ViewController ()
14 |
15 | @end
16 |
17 | @implementation ViewController
18 |
19 | - (void)viewDidLoad {
20 | [super viewDidLoad];
21 | // Do any additional setup after loading the view, typically from a nib.
22 |
23 | ViewModel * vm = [[ViewModel alloc]init];
24 |
25 | //取到command信号中的信号,对其进行订阅
26 | [vm.command.executionSignals.switchToLatest subscribeNext:^(id x) {
27 | NSLog(@"%@",x);
28 | } error:^(NSError *error) {
29 | NSLog(@"%@",error);
30 | } completed:^{
31 | NSLog(@"完成");
32 | }];
33 |
34 | //取到command信号
35 | [vm.command.executionSignals subscribeNext:^(id x) {
36 |
37 | NSLog(@"-------------------------%@",[x class]);
38 |
39 | NSLog(@"这里获取到的x是一个带有数据的信号,需要对x做进一步订阅就可以获取到数据如上所示");
40 |
41 | }];
42 |
43 | //监听命令是否完成
44 | [vm.command.executing subscribeNext:^(id x) {
45 |
46 | //这里的x是一个带有数据的信号,若这个信号存在那么就说明command还在执行,否则说明没有执行或者执行完毕
47 | if ([x boolValue]) {
48 | NSLog(@"正在执行");
49 | } else {
50 | NSLog(@"执行未开始/执行完毕");
51 | }
52 | }];
53 |
54 | //必须要加这句话,否则command无法执行,excute传的参数若无用可以为nil,传的参数就是viewModel中RACCommand中block的input值,根据这个值我们可以做许多事情
55 | //例如,封装一个tableview的翻页请求,每次翻页的时候可以通过excute把翻页的页码给他
56 | [vm.command execute:nil];
57 | }
58 |
59 | @end
60 |
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/the basis of RACCommand/ViewModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewModel.h
3 | // the basis of RACCommand
4 | //
5 | // Created by fy on 16/8/22.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #import
12 |
13 | @interface ViewModel : NSObject
14 |
15 | //这里需要对command进行强引用,否则无法执行
16 | @property(nonatomic,strong)RACCommand * command;
17 |
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/the basis of RACCommand/ViewModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewModel.m
3 | // the basis of RACCommand
4 | //
5 | // Created by fy on 16/8/22.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "ViewModel.h"
10 |
11 | #import "FYRequestTool.h"
12 |
13 | @implementation ViewModel
14 |
15 | //这里使用懒加载对command赋值
16 | -(RACCommand *)command{
17 |
18 | if (nil == _command) {
19 |
20 | [self loadInfo];
21 | }
22 | return _command;
23 | }
24 |
25 | -(void)loadInfo{
26 |
27 | //input就是控制器中,viewmodel执行command时excute传入的参数
28 | RACCommand * command = [[RACCommand alloc]initWithSignalBlock:^RACSignal *(id input) {
29 |
30 | //command必须有信号返回值,如果没有的话可以为[RACSignal empty]
31 | return [RACSignal createSignal:^RACDisposable *(id subscriber)
32 | {
33 | NSMutableDictionary * params = [NSMutableDictionary dictionary];
34 |
35 | params[@"build"] = @"3360";
36 | params[@"channel"] = @"appstore";
37 | params[@"plat"] = @"2";
38 |
39 | [FYRequestTool GET:@"http://app.bilibili.com/x/banner" parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
40 |
41 | [subscriber sendNext:responseObject];
42 | //发送完信号必须发送完成信号,否则无法执行
43 | [subscriber sendCompleted];
44 |
45 | } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
46 |
47 | [subscriber sendError:error];
48 |
49 | }];
50 |
51 | return [RACDisposable disposableWithBlock:^{
52 |
53 | [FYRequestTool cancel];
54 |
55 | NSLog(@"这里面可以写取消请求,完成信号后请求会取消");
56 |
57 | }];
58 | }];
59 | }];
60 |
61 | //必须强引用这个command,否则无法执行
62 | self.command = command;
63 |
64 | }
65 |
66 | @end
67 |
--------------------------------------------------------------------------------
/basic/the basis of RACCommand/the basis of RACCommand/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // the basis of RACCommand
4 | //
5 | // Created by fy on 16/8/22.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/basic/the basis of RACSignal/Podfile:
--------------------------------------------------------------------------------
1 | # Uncomment this line to define a global platform for your project
2 | # platform :ios, '9.0'
3 |
4 | target 'the basis of RACSignal' do
5 | # Uncomment this line if you're using Swift or would like to use dynamic frameworks
6 | use_frameworks!
7 |
8 | # Pods for the basis of RACSignal
9 |
10 | pod 'ReactiveCocoa'
11 |
12 | end
13 |
--------------------------------------------------------------------------------
/basic/the basis of RACSignal/Podfile.lock:
--------------------------------------------------------------------------------
1 | PODS:
2 | - ReactiveCocoa (4.2.1):
3 | - Result (~> 2.0)
4 | - Result (2.1.3)
5 |
6 | DEPENDENCIES:
7 | - ReactiveCocoa
8 |
9 | SPEC CHECKSUMS:
10 | ReactiveCocoa: 5a42745f11ea236f405bb9ce5e97c5e3b23562dd
11 | Result: 18e1a7597fbcca5923c565b40a25a98afafdee02
12 |
13 | PODFILE CHECKSUM: 6e963b2ffad318e9f050f95651d9bd8c810463d8
14 |
15 | COCOAPODS: 1.0.1
16 |
--------------------------------------------------------------------------------
/basic/the basis of RACSignal/the basis of RACSignal.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/basic/the basis of RACSignal/the basis of RACSignal.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/basic/the basis of RACSignal/the basis of RACSignal/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // the basis of RACSignal
4 | //
5 | // Created by fy on 16/8/15.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/basic/the basis of RACSignal/the basis of RACSignal/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // the basis of RACSignal
4 | //
5 | // Created by fy on 16/8/15.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | @interface AppDelegate ()
12 |
13 | @end
14 |
15 | @implementation AppDelegate
16 |
17 |
18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19 | // Override point for customization after application launch.
20 | return YES;
21 | }
22 |
23 | - (void)applicationWillResignActive:(UIApplication *)application {
24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
26 | }
27 |
28 | - (void)applicationDidEnterBackground:(UIApplication *)application {
29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
31 | }
32 |
33 | - (void)applicationWillEnterForeground:(UIApplication *)application {
34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
35 | }
36 |
37 | - (void)applicationDidBecomeActive:(UIApplication *)application {
38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
39 | }
40 |
41 | - (void)applicationWillTerminate:(UIApplication *)application {
42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
43 | }
44 |
45 | @end
46 |
--------------------------------------------------------------------------------
/basic/the basis of RACSignal/the basis of RACSignal/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/basic/the basis of RACSignal/the basis of RACSignal/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/basic/the basis of RACSignal/the basis of RACSignal/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
78 |
84 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
--------------------------------------------------------------------------------
/basic/the basis of RACSignal/the basis of RACSignal/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/basic/the basis of RACSignal/the basis of RACSignal/PersonModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // PersonModel.h
3 | // the basis of RACSignal
4 | //
5 | // Created by fy on 16/8/15.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface PersonModel : NSObject
12 |
13 | @property(nonatomic,copy)NSString * name;
14 |
15 | @property(nonatomic,assign)int age;
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/basic/the basis of RACSignal/the basis of RACSignal/PersonModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // PersonModel.m
3 | // the basis of RACSignal
4 | //
5 | // Created by fy on 16/8/15.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "PersonModel.h"
10 |
11 | @implementation PersonModel
12 |
13 | -(NSString *)description{
14 |
15 | NSArray * keys = @[@"name",@"age"];
16 |
17 | return [self dictionaryWithValuesForKeys:keys].description;
18 | }
19 |
20 | @end
21 |
--------------------------------------------------------------------------------
/basic/the basis of RACSignal/the basis of RACSignal/PersonViewModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // PersonViewModel.h
3 | // the basis of RACSignal
4 | //
5 | // Created by fy on 16/8/15.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #import "PersonModel.h"
12 |
13 | #import
14 |
15 | @interface PersonViewModel : NSObject
16 |
17 | -(RACSignal*)loadInfo;
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/basic/the basis of RACSignal/the basis of RACSignal/PersonViewModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // PersonViewModel.m
3 | // the basis of RACSignal
4 | //
5 | // Created by fy on 16/8/15.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "PersonViewModel.h"
10 |
11 | @interface PersonViewModel()
12 |
13 | @property(nonatomic,strong)NSMutableArray * dataArray;
14 |
15 | @end
16 |
17 | @implementation PersonViewModel
18 |
19 | #pragma mark - 读取数据 -
20 | -(RACSignal *)loadInfo{
21 |
22 |
23 | return [RACSignal createSignal:^RACDisposable *(id subscriber) {
24 |
25 | BOOL isError = NO;
26 |
27 | if (isError) {
28 |
29 | //发送错误信息
30 | [subscriber sendError:[NSError errorWithDomain:@"github.com/SkyHarute" code:2333 userInfo:@{@"errorMessage":@"异常错误"}]];
31 |
32 | } else {
33 |
34 | //创建信息(只需要知道是给_dataArray赋值就可以)
35 | [self creatInfo];
36 | //若没有错误发送正确信息,并将数组送出
37 | [subscriber sendNext:_dataArray];
38 |
39 | }
40 |
41 | //正确信息发送完毕后发送完成信号,若信息为错误信息则不发送完成信号
42 | [subscriber sendCompleted];
43 |
44 | return nil;
45 | }];
46 | }
47 |
48 | #pragma mark - 创建数据 -
49 | -(void)creatInfo{
50 |
51 | _dataArray = [NSMutableArray array];
52 |
53 | for (int i =0; i<20; i++) {
54 |
55 | PersonModel * model = [[PersonModel alloc]init];
56 |
57 | model.name = [@"zhangsan" stringByAppendingFormat:@"%d",i];
58 | model.age = 15 + arc4random_uniform(20);
59 |
60 | [_dataArray addObject:model];
61 | }
62 | }
63 | @end
64 |
--------------------------------------------------------------------------------
/basic/the basis of RACSignal/the basis of RACSignal/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // the basis of RACSignal
4 | //
5 | // Created by fy on 16/8/15.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UIViewController
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/basic/the basis of RACSignal/the basis of RACSignal/ViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // the basis of RACSignal
4 | //
5 | // Created by fy on 16/8/15.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "ViewController.h"
10 |
11 | #import "PersonViewModel.h"
12 |
13 | @interface ViewController ()
14 |
15 | @property (weak, nonatomic) IBOutlet UIButton *btn_event;
16 |
17 | @property (weak, nonatomic) IBOutlet UITextField *tf_age;
18 |
19 | @property (weak, nonatomic) IBOutlet UITextField *tf_name;
20 |
21 | @property (weak, nonatomic) IBOutlet UILabel *lb_name;
22 |
23 | @property (weak, nonatomic) IBOutlet UILabel *lb_age;
24 |
25 | @property (strong, nonatomic)NSArray * dataArray;
26 | @end
27 |
28 | @implementation ViewController
29 |
30 | #pragma mark - 生命周期 -
31 | - (void)viewDidLoad {
32 | [super viewDidLoad];
33 | // Do any additional setup after loading the view, typically from a nib.
34 |
35 | //获取信息
36 | [self getInfo];
37 |
38 | //处理事件
39 | [self handlingEvents];
40 |
41 | // [self twoWayBinding];
42 | }
43 | #warning RAC在使用的时候由于系统提供的信号是始终存在的,所以在block中使用属性或者成员变量几乎都会涉及到一个循环引用的问题,有两种方法可以解决,使用weakself解决或者RAC提供的weak-strong dance
44 | //在 block 的外部使用 @weakify(self)
45 | //在 block 的内部使用 @strongify(self)
46 | -(void)dealloc{
47 |
48 | NSLog(@"已销毁");
49 | }
50 |
51 | #pragma mark - 获取信息 -
52 | -(void)getInfo{
53 |
54 | PersonViewModel * viewModel = [[PersonViewModel alloc]init];
55 |
56 | //这是signal对象方法中能把三种情况全部列举出来的对象方法,根据需求决定,一般使用最简单的就好
57 | [[viewModel loadInfo] subscribeNext:^(id x) {
58 |
59 | //接收到正常发送信号,并打印信号传过来的信息
60 | NSLog(@"%@",x);
61 |
62 | self.dataArray = [NSArray array];
63 |
64 | self.dataArray = x;
65 |
66 | } error:^(NSError *error) {
67 |
68 | //接收到错误信号,并打印出错误信息
69 | NSLog(@"%@",error);
70 |
71 | } completed:^{
72 |
73 | //接收到完成信号,并打印出完成信息,若为错误信号则不打印
74 | NSLog(@"完成");
75 |
76 | }];
77 | }
78 |
79 | #pragma mark - 处理事件 -
80 | -(void)handlingEvents{
81 | @weakify(self);
82 |
83 | //按钮点击
84 | [[self.btn_event rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
85 |
86 | @strongify(self);
87 | NSLog(@"%@",self.dataArray.firstObject);
88 |
89 | }];
90 |
91 |
92 | //name输入框输入内容实时监听
93 | [[self.tf_name rac_textSignal] subscribeNext:^(id x) {
94 | NSLog(@"%@",x);
95 | }];
96 |
97 | //年龄输入框输入内容实时监听
98 | [[self.tf_age rac_textSignal] subscribeNext:^(id x) {
99 | NSLog(@"%@",x);
100 | }];
101 |
102 | //信号组合获取,注意将id类型改为RACTuple
103 | [[RACSignal combineLatest:@[self.tf_name.rac_textSignal,self.tf_age.rac_textSignal]] subscribeNext:^(RACTuple *x) {
104 |
105 | NSString * name = x.first;
106 |
107 | NSString * age = x.second;
108 |
109 | NSLog(@"name:%@,age:%@",name,age);
110 | }];
111 |
112 | //根据textfield内容决定按钮是否可以点击
113 | // reduce 中,可以通过接收的参数进行计算,并且返回需要的数值!
114 | [[RACSignal combineLatest:@[self.tf_name.rac_textSignal,self.tf_age.rac_textSignal] reduce:^id(NSString * name , NSString * age){
115 |
116 | return @(name.length>0&&age.length>0);
117 |
118 | }] subscribeNext:^(id x) {
119 |
120 | @strongify(self);
121 |
122 | self.btn_event.enabled = [x boolValue];
123 |
124 | }];
125 |
126 | }
127 |
128 | #pragma mark - 双向绑定 -
129 | -(void)twoWayBinding{
130 |
131 | //一般双向绑定是指UI控件和模型互相绑定的,一般是在在改变一个值的情况下另外一个对象也会改变,类似KVO;
132 | //这里为了更好的体现出效果所以采用了textfield绑定到模型,模型绑定到label的做法,比较好理解
133 |
134 | //UI绑定模型
135 | PersonModel * model = [[PersonModel alloc]init];
136 |
137 | model = self.dataArray.firstObject;
138 |
139 | RAC(self.lb_name,text)=RACObserve(model, name);
140 |
141 | #warning 这里不能使用基本数据类型,RAC中传递的都是id类型,使用基本类型会崩溃
142 | RAC(self.lb_age,text)=[RACObserve(model, age) map:^id(id value) {
143 | return [value description];
144 | }];
145 | //模型到UI
146 | [[RACSignal combineLatest:@[self.tf_name.rac_textSignal,self.tf_age.rac_textSignal]] subscribeNext:^(RACTuple * x) {
147 |
148 | model.name = x.first;
149 | model.age = [x.second intValue];
150 | }];
151 |
152 | //直接双向绑定
153 | // RACChannelTo(self.lb_name,text) = RACChannelTo(model, name);
154 |
155 | }
156 |
157 |
158 |
159 | @end
160 |
--------------------------------------------------------------------------------
/basic/the basis of RACSignal/the basis of RACSignal/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // the basis of RACSignal
4 | //
5 | // Created by fy on 16/8/15.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/Podfile:
--------------------------------------------------------------------------------
1 | # Uncomment this line to define a global platform for your project
2 | platform :ios, '9.0'
3 |
4 | target 'the basis of RACSubject' do
5 | # Uncomment this line if you're using Swift or would like to use dynamic frameworks
6 | use_frameworks!
7 |
8 | # Pods for the basis of RACSubject
9 |
10 | pod 'ReactiveCocoa'
11 | end
12 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/Podfile.lock:
--------------------------------------------------------------------------------
1 | PODS:
2 | - ReactiveCocoa (4.2.1):
3 | - Result (~> 2.0)
4 | - Result (2.1.3)
5 |
6 | DEPENDENCIES:
7 | - ReactiveCocoa
8 |
9 | SPEC CHECKSUMS:
10 | ReactiveCocoa: 5a42745f11ea236f405bb9ce5e97c5e3b23562dd
11 | Result: 18e1a7597fbcca5923c565b40a25a98afafdee02
12 |
13 | PODFILE CHECKSUM: ba07b02926268155c1f9b9b19e04bea0033c281e
14 |
15 | COCOAPODS: 1.0.1
16 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // the basis of RACSubject
4 | //
5 | // Created by fy on 16/8/18.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // the basis of RACSubject
4 | //
5 | // Created by fy on 16/8/18.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | @interface AppDelegate ()
12 |
13 | @end
14 |
15 | @implementation AppDelegate
16 |
17 |
18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19 | // Override point for customization after application launch.
20 | return YES;
21 | }
22 |
23 | - (void)applicationWillResignActive:(UIApplication *)application {
24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
26 | }
27 |
28 | - (void)applicationDidEnterBackground:(UIApplication *)application {
29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
31 | }
32 |
33 | - (void)applicationWillEnterForeground:(UIApplication *)application {
34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
35 | }
36 |
37 | - (void)applicationDidBecomeActive:(UIApplication *)application {
38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
39 | }
40 |
41 | - (void)applicationWillTerminate:(UIApplication *)application {
42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
43 | }
44 |
45 | @end
46 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/AppleModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppleModel.h
3 | // the basis of RACSubject
4 | //
5 | // Created by fy on 16/8/18.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppleModel : NSObject
12 |
13 | @property(nonatomic,copy)NSString * price;
14 |
15 | @property(nonatomic,copy)NSString * weight;
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/AppleModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppleModel.m
3 | // the basis of RACSubject
4 | //
5 | // Created by fy on 16/8/18.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "AppleModel.h"
10 |
11 | @implementation AppleModel
12 |
13 | -(NSString *)description{
14 |
15 | NSArray * keys = @[@"price",@"weight"];
16 |
17 | return [self dictionaryWithValuesForKeys:keys].description;
18 | }
19 |
20 | @end
21 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/AppleViewModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppleViewModel.h
3 | // the basis of RACSubject
4 | //
5 | // Created by fy on 16/8/18.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #import
12 |
13 | #import "AppleModel.h"
14 |
15 | @interface AppleViewModel : NSObject
16 |
17 |
18 | -(RACReplaySubject* )loadInfo;
19 |
20 | @end
21 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/AppleViewModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppleViewModel.m
3 | // the basis of RACSubject
4 | //
5 | // Created by fy on 16/8/18.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "AppleViewModel.h"
10 |
11 | @interface AppleViewModel ()
12 |
13 | @property(nonatomic,strong)NSMutableArray * dataArray;
14 |
15 | @end
16 |
17 | @implementation AppleViewModel
18 |
19 | -(RACReplaySubject* )loadInfo{
20 |
21 | RACReplaySubject * replaySubject = [RACReplaySubject subject];
22 |
23 | BOOL isError = NO;
24 |
25 | if (isError) {
26 | [replaySubject sendError:[NSError errorWithDomain:@"github.com/SkyHarute" code:2333 userInfo:@{@"errorMessage":@"异常错误"}]];
27 | } else {
28 |
29 | [self creatInfo];
30 |
31 | [replaySubject sendNext:self.dataArray];
32 | }
33 |
34 | [replaySubject sendCompleted];
35 |
36 | return replaySubject;
37 | }
38 |
39 | #pragma mark - 创建数据 -
40 | -(void)creatInfo{
41 |
42 | _dataArray = [NSMutableArray array];
43 |
44 | for (int i =0; i<20; i++) {
45 |
46 | AppleModel * model = [[AppleModel alloc]init];
47 |
48 | model.price = [NSString stringWithFormat:@"%@",@(1 + arc4random_uniform(3))];
49 | model.weight =[NSString stringWithFormat:@"%@",@(15 + arc4random_uniform(20))];
50 |
51 | [_dataArray addObject:model];
52 | }
53 |
54 | NSLog(@"%@",self.dataArray);
55 | }
56 |
57 | @end
58 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/DelegateSecondVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // DelegateSecondVC.h
3 | // the basis of RACSubject
4 | //
5 | // Created by fy on 16/8/18.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #import
12 |
13 | @interface DelegateSecondVC : UIViewController
14 |
15 | @property(nonatomic,strong)RACSubject * delagetaSubject;
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/DelegateSecondVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // DelegateSecondVC.m
3 | // the basis of RACSubject
4 | //
5 | // Created by fy on 16/8/18.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "DelegateSecondVC.h"
10 |
11 | @interface DelegateSecondVC ()
12 |
13 | @end
14 |
15 | @implementation DelegateSecondVC
16 |
17 | - (void)viewDidLoad {
18 | [super viewDidLoad];
19 | // Do any additional setup after loading the view from its nib.
20 | }
21 |
22 | - (IBAction)didClickBtn:(UIButton *)sender {
23 |
24 | if (self.delagetaSubject) {
25 | [self.delagetaSubject sendNext:@"haha"];
26 |
27 | //若想要持续代理必须注释掉这一步
28 | // [self.delagetaSubject sendCompleted];
29 | }
30 | }
31 |
32 |
33 | @end
34 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/DelegateSecondVC.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/PersonModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // PersonModel.h
3 | // the basis of RACSignal
4 | //
5 | // Created by fy on 16/8/15.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface PersonModel : NSObject
12 |
13 | @property(nonatomic,copy)NSString * name;
14 |
15 | @property(nonatomic,assign)int age;
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/PersonModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // PersonModel.m
3 | // the basis of RACSignal
4 | //
5 | // Created by fy on 16/8/15.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "PersonModel.h"
10 |
11 | @implementation PersonModel
12 |
13 | -(NSString *)description{
14 |
15 | NSArray * keys = @[@"name",@"age"];
16 |
17 | return [self dictionaryWithValuesForKeys:keys].description;
18 | }
19 |
20 | @end
21 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/PersonViewModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // PersonViewModel.h
3 | // the basis of RACSignal
4 | //
5 | // Created by fy on 16/8/15.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #import "PersonModel.h"
12 |
13 | #import
14 |
15 | @interface PersonViewModel : NSObject
16 |
17 | -(RACSubject *)getSubject;
18 |
19 | -(void)loadInfo;
20 |
21 | @end
22 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/PersonViewModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // PersonViewModel.m
3 | // the basis of RACSignal
4 | //
5 | // Created by fy on 16/8/15.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "PersonViewModel.h"
10 |
11 | @interface PersonViewModel()
12 |
13 | @property(nonatomic,strong)NSMutableArray * dataArray;
14 |
15 | @property(nonatomic,strong)RACSubject * subject;
16 |
17 | @end
18 |
19 | @implementation PersonViewModel
20 |
21 | #pragma mark - 读取数据 -
22 |
23 | -(RACSubject *)getSubject{
24 |
25 | RACSubject * subject = [RACSubject subject];
26 |
27 | self.subject = subject;
28 |
29 | return subject;
30 |
31 | }
32 | -( void)loadInfo{
33 |
34 |
35 | BOOL isError = NO;
36 |
37 | if (isError) {
38 | [self.subject sendError:[NSError errorWithDomain:@"github.com/SkyHarute" code:2333 userInfo:@{@"errorMessage":@"异常错误"}]];
39 | }else{
40 |
41 | [self creatInfo];
42 |
43 | [self.subject sendNext:_dataArray];
44 | }
45 |
46 | [self.subject sendCompleted];
47 |
48 | }
49 |
50 | #pragma mark - 创建数据 -
51 | -(void)creatInfo{
52 |
53 | _dataArray = [NSMutableArray array];
54 |
55 | for (int i =0; i<20; i++) {
56 |
57 | PersonModel * model = [[PersonModel alloc]init];
58 |
59 | model.name = [@"zhangsan" stringByAppendingFormat:@"%d",i];
60 | model.age = 15 + arc4random_uniform(20);
61 |
62 | [_dataArray addObject:model];
63 | }
64 | }
65 | @end
66 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/RACReplaySubjectVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // RACReplaySubjectVC.h
3 | // the basis of RACSubject
4 | //
5 | // Created by fy on 16/8/18.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface RACReplaySubjectVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/RACReplaySubjectVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // RACReplaySubjectVC.m
3 | // the basis of RACSubject
4 | //
5 | // Created by fy on 16/8/18.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "RACReplaySubjectVC.h"
10 |
11 | #import "AppleViewModel.h"
12 |
13 | @interface RACReplaySubjectVC ()
14 |
15 | @end
16 |
17 | @implementation RACReplaySubjectVC
18 |
19 | - (void)viewDidLoad {
20 | [super viewDidLoad];
21 | // Do any additional setup after loading the view from its nib.
22 |
23 | [self createUI];
24 |
25 | [self getInfo];
26 | }
27 |
28 | #pragma mark - UI -
29 | -(void)createUI{
30 |
31 | self.navigationItem.title = @"RACReplaySubject";
32 | }
33 |
34 | //RACReplaySubject对于订阅和发送信号的顺序掌握的比较宽松,可以先发送信号在进行订阅也可以
35 | -(void)getInfo{
36 |
37 | AppleViewModel * viewModel = [[AppleViewModel alloc]init];
38 |
39 | [[viewModel loadInfo] subscribeNext:^(id x) {
40 |
41 | NSLog(@"%@",x);
42 |
43 | } error:^(NSError *error) {
44 |
45 | NSLog(@"%@",error);
46 |
47 | } completed:^{
48 |
49 | NSLog(@"完成");
50 | }];
51 | }
52 |
53 | @end
54 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/RACReplaySubjectVC.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/RACSubjectDelegateVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // RACSubjectDelegateVC.h
3 | // the basis of RACSubject
4 | //
5 | // Created by fy on 16/8/18.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface RACSubjectDelegateVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/RACSubjectDelegateVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // RACSubjectDelegateVC.m
3 | // the basis of RACSubject
4 | //
5 | // Created by fy on 16/8/18.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "RACSubjectDelegateVC.h"
10 |
11 | #import "DelegateSecondVC.h"
12 |
13 | @interface RACSubjectDelegateVC ()
14 |
15 | @property(nonatomic,strong)RACSubject * subject;
16 |
17 | @end
18 |
19 | @implementation RACSubjectDelegateVC
20 |
21 | - (void)viewDidLoad {
22 | [super viewDidLoad];
23 | // Do any additional setup after loading the view from its nib.
24 |
25 | self.navigationItem.title = @"RACSubjectDelegate";
26 |
27 | }
28 | //跳转到第二个页面
29 | - (IBAction)didClickNextBtn:(UIButton *)sender {
30 |
31 | DelegateSecondVC * vc = [[DelegateSecondVC alloc] init];
32 |
33 | RACSubject * subject = [RACSubject subject];
34 | //将即将跳转的控制器对其RACSubject属性进行赋值,如果跳转页要让他的代理来做什么只需要发送响应的信号就可以了
35 | vc.delagetaSubject = subject;
36 |
37 | self.subject = subject;
38 | //这里有个原则,那就是还是要先订阅在发送信号
39 | [self getInfo];
40 |
41 | [self.navigationController pushViewController:vc animated:YES];
42 | }
43 |
44 | #pragma mark - 订阅信号 -
45 | -(void)getInfo{
46 |
47 | [self.subject subscribeNext:^(id x) {
48 | NSLog(@"%@",x);
49 | } error:^(NSError *error) {
50 | NSLog(@"%@",error);
51 | } completed:^{
52 | NSLog(@"完成");
53 | }];
54 | }
55 |
56 | @end
57 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/RACSubjectDelegateVC.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/RACSubjectVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // RACSubjectVC.h
3 | // the basis of RACSubject
4 | //
5 | // Created by fy on 16/8/18.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface RACSubjectVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/RACSubjectVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // RACSubjectVC.m
3 | // the basis of RACSubject
4 | //
5 | // Created by fy on 16/8/18.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "RACSubjectVC.h"
10 |
11 | #import "PersonViewModel.h"
12 |
13 | @interface RACSubjectVC ()
14 |
15 | @end
16 |
17 | @implementation RACSubjectVC
18 |
19 | #pragma mark - 生命周期 -
20 | - (void)viewDidLoad {
21 | [super viewDidLoad];
22 | // Do any additional setup after loading the view from its nib.
23 |
24 | [self createUI];
25 |
26 | [self getInfo];
27 | }
28 |
29 | #pragma mark - UI -
30 | -(void)createUI{
31 |
32 | self.navigationItem.title = @"RACSubject";
33 | }
34 |
35 | -(void)getInfo{
36 |
37 | PersonViewModel * viewModel = [[PersonViewModel alloc]init];
38 |
39 | //这是错误做法,先发送信号再订阅信号的话对于RACSubject来说的话是不可以的,RACReplaySubject可以先发送信号再去订阅
40 | // [viewModel loadInfo];
41 |
42 | //先获取到RACSubject,再订阅他,和RACSignal基本相同的方式
43 | [[viewModel getSubject] subscribeNext:^(id x) {
44 |
45 | NSLog(@"%@",x);
46 | } error:^(NSError *error) {
47 | NSLog(@"%@",error);
48 | } completed:^{
49 | NSLog(@"完成");
50 | }];
51 |
52 | //发送信号
53 | [viewModel loadInfo];
54 | }
55 | @end
56 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/RACSubjectVC.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // the basis of RACSubject
4 | //
5 | // Created by fy on 16/8/18.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UIViewController
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/ViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // the basis of RACSubject
4 | //
5 | // Created by fy on 16/8/18.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "ViewController.h"
10 |
11 | #import "RACSubjectVC.h"
12 |
13 | #import "RACReplaySubjectVC.h"
14 |
15 | #import "RACSubjectDelegateVC.h"
16 |
17 | @interface ViewController ()
18 |
19 | @property (weak, nonatomic) IBOutlet UITableView *tableView;
20 |
21 | @end
22 |
23 | @implementation ViewController
24 |
25 | static NSString * identifier = @"cell";
26 |
27 | #pragma mark - 生命周期 -
28 | - (void)viewDidLoad {
29 | [super viewDidLoad];
30 | // Do any additional setup after loading the view, typically from a nib.
31 |
32 | [self createUI];
33 | }
34 |
35 | #pragma mark - UI -
36 | -(void)createUI{
37 |
38 | self.tableView.dataSource = self;
39 |
40 | self.tableView.delegate = self;
41 |
42 | //取消tableview顶部空白
43 | self.automaticallyAdjustsScrollViewInsets = NO;
44 |
45 | [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:identifier];
46 |
47 | }
48 |
49 | #pragma mark - 数据源方法 -
50 | -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
51 |
52 | return 1;
53 | }
54 |
55 | -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
56 |
57 | return 3;
58 | }
59 |
60 | -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
61 |
62 | UITableViewCell * cell =[tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
63 |
64 | switch (indexPath.row) {
65 | case 0:
66 | cell.textLabel.text = @"RACSubject";
67 | break;
68 |
69 | case 1:
70 | cell.textLabel.text = @"RACReplaySubject";
71 | break;
72 |
73 | case 2:
74 | cell.textLabel.text = @"RACSubject代替代理";
75 | break;
76 |
77 | default:
78 | break;
79 | }
80 |
81 | cell.selectionStyle = UITableViewCellSelectionStyleNone;
82 |
83 | return cell;
84 | }
85 |
86 | #pragma mark - 代理方法 -
87 |
88 | //设置组头组尾高度
89 | -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
90 |
91 | return 0.1f;
92 | }
93 |
94 | -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
95 | return 0.1f;
96 | }
97 |
98 | -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
99 |
100 | switch (indexPath.row) {
101 | case 0:
102 | {
103 | RACSubjectVC * vc = [[RACSubjectVC alloc]init];
104 |
105 | [self.navigationController pushViewController:vc animated:YES];
106 |
107 | break;
108 | }
109 | case 1:
110 | {
111 | RACReplaySubjectVC * vc = [[RACReplaySubjectVC alloc]init];
112 |
113 | [self.navigationController pushViewController:vc animated:YES];
114 |
115 | break;
116 | }
117 |
118 | case 2:
119 | {
120 |
121 | RACSubjectDelegateVC * vc = [[RACSubjectDelegateVC alloc] init];
122 |
123 | [self.navigationController pushViewController:vc animated:YES];
124 |
125 | break;
126 | }
127 |
128 | default:
129 |
130 | break;
131 | }
132 | }
133 | @end
134 |
--------------------------------------------------------------------------------
/basic/the basis of RACSubject/the basis of RACSubject/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // the basis of RACSubject
4 | //
5 | // Created by fy on 16/8/18.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/MainVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // MainVC.h
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/24.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface MainVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/MainVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // MainVC.m
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/24.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "MainVC.h"
10 |
11 | #import "DelegateVC.h"
12 |
13 | #import "KVOVC.h"
14 |
15 | #import "EventVC.h"
16 |
17 | #import "NSNotificationVC.h"
18 |
19 | #import "TimerVC.h"
20 |
21 | #import "TargetOfUISignalVC.h"
22 |
23 | @interface MainVC ()
24 |
25 | @end
26 |
27 | @implementation MainVC
28 |
29 | - (void)viewDidLoad {
30 | [super viewDidLoad];
31 | // Do any additional setup after loading the view from its nib.
32 |
33 | self.view.backgroundColor = [UIColor whiteColor];
34 |
35 | [self setupUI];
36 | }
37 |
38 |
39 | #pragma mark - UI -
40 |
41 | -(void)setupUI{
42 |
43 | UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
44 |
45 | [self.view addSubview:tableview];
46 |
47 | [tableview mas_makeConstraints:^(MASConstraintMaker *make) {
48 |
49 | make.edges.equalTo(0);
50 |
51 | }];
52 |
53 | tableview.dataSource = self;
54 |
55 | tableview.delegate = self;
56 |
57 | [tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
58 |
59 | }
60 |
61 | #pragma mark - 数据源方法 -
62 | -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
63 |
64 | return 1;
65 |
66 | }
67 |
68 | -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
69 |
70 | return 6;
71 |
72 | }
73 |
74 | -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
75 |
76 | UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
77 |
78 | cell.selectionStyle = UITableViewCellSelectionStyleNone;
79 |
80 | switch (indexPath.row) {
81 | case 0:
82 | cell.textLabel.text = @"代替代理";
83 | break;
84 |
85 | case 1:
86 | cell.textLabel.text = @"代替KVO";
87 | break;
88 |
89 | case 2:
90 | cell.textLabel.text = @"监听事件";
91 | break;
92 |
93 | case 3:
94 | cell.textLabel.text = @"代替通知";
95 | break;
96 |
97 | case 4:
98 | cell.textLabel.text = @"代替定时器";
99 | break;
100 |
101 | case 5:
102 | cell.textLabel.text = @"代替UI控件的addtarget";
103 | break;
104 |
105 | default:
106 | break;
107 | }
108 |
109 | return cell;
110 | }
111 |
112 | #pragma mark - 代理方法 -
113 | -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
114 |
115 |
116 | switch (indexPath.row) {
117 |
118 | case 0:
119 | {
120 | DelegateVC * vc = [[DelegateVC alloc]init];
121 |
122 | [self.navigationController pushViewController:vc animated:YES];
123 |
124 | break;
125 | }
126 | case 1:
127 | {
128 | KVOVC * vc = [[KVOVC alloc]init];
129 |
130 | [self.navigationController pushViewController:vc animated:YES];
131 |
132 | break;
133 | }
134 | case 2:
135 | {
136 | EventVC * vc = [[EventVC alloc]init];
137 |
138 | [self.navigationController pushViewController:vc animated:YES];
139 |
140 | break;
141 | }
142 |
143 | case 3:
144 | {
145 | NSNotificationVC * vc = [[NSNotificationVC alloc]init];
146 |
147 | [self.navigationController pushViewController:vc animated:YES];
148 |
149 | break;
150 | }
151 |
152 | case 4:
153 | {
154 | TimerVC * vc = [[TimerVC alloc]init];
155 |
156 | [self.navigationController pushViewController:vc animated:YES];
157 |
158 | break;
159 | }
160 |
161 | case 5:
162 | {
163 | TargetOfUISignalVC * vc = [[TargetOfUISignalVC alloc]init];
164 |
165 | [self.navigationController pushViewController:vc animated:YES];
166 |
167 | break;
168 | }
169 |
170 | default:
171 | break;
172 | }
173 | }
174 |
175 |
176 | @end
177 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/MainVC.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/Podfile:
--------------------------------------------------------------------------------
1 | # Uncomment this line to define a global platform for your project
2 | platform :ios, '9.0'
3 |
4 | target 'the skills of RAC' do
5 | # Uncomment this line if you're using Swift or would like to use dynamic frameworks
6 | use_frameworks!
7 |
8 | # Pods for the skills of RAC
9 | pod ‘ReactiveCocoa’
10 | pod 'Masonry'
11 | end
12 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/Podfile.lock:
--------------------------------------------------------------------------------
1 | PODS:
2 | - Masonry (1.0.1)
3 | - ReactiveCocoa (4.2.1):
4 | - Result (~> 2.0)
5 | - Result (2.1.3)
6 |
7 | DEPENDENCIES:
8 | - Masonry
9 | - ReactiveCocoa
10 |
11 | SPEC CHECKSUMS:
12 | Masonry: a1a931a0d08870ed8ae415a2ea5ea68ebcac77df
13 | ReactiveCocoa: 5a42745f11ea236f405bb9ce5e97c5e3b23562dd
14 | Result: 18e1a7597fbcca5923c565b40a25a98afafdee02
15 |
16 | PODFILE CHECKSUM: 5a598bbb3962df003bb428e4b0681a864e695bdb
17 |
18 | COCOAPODS: 1.0.1
19 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/24.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/24.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | #import "MainVC.h"
12 |
13 | #define screedSize [UIScreen mainScreen].bounds
14 |
15 | @interface AppDelegate ()
16 |
17 | @end
18 |
19 | @implementation AppDelegate
20 |
21 |
22 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
23 | // Override point for customization after application launch.
24 |
25 | self.window = [[UIWindow alloc]initWithFrame:screedSize];
26 |
27 | MainVC * VC = [[MainVC alloc]init];
28 |
29 | UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:VC];
30 |
31 | self.window.rootViewController = nav;
32 |
33 | [self.window makeKeyAndVisible];
34 |
35 | return YES;
36 | }
37 |
38 | - (void)applicationWillResignActive:(UIApplication *)application {
39 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
40 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
41 | }
42 |
43 | - (void)applicationDidEnterBackground:(UIApplication *)application {
44 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
45 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
46 | }
47 |
48 | - (void)applicationWillEnterForeground:(UIApplication *)application {
49 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
50 | }
51 |
52 | - (void)applicationDidBecomeActive:(UIApplication *)application {
53 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
54 | }
55 |
56 | - (void)applicationWillTerminate:(UIApplication *)application {
57 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
58 | }
59 |
60 | @end
61 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/DelegateVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // DelegateVC.h
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/24.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface DelegateVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/DelegateVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // DelegateVC.m
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/24.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "DelegateVC.h"
10 |
11 | @interface DelegateVC ()
12 |
13 | @end
14 |
15 | @implementation DelegateVC
16 |
17 | - (void)viewDidLoad {
18 | [super viewDidLoad];
19 | // Do any additional setup after loading the view from its nib.
20 |
21 | [self setupUI];
22 | }
23 |
24 | #pragma mark - UI -
25 |
26 | -(void)setupUI{
27 |
28 | UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
29 |
30 | [self.view addSubview:tableview];
31 |
32 | [tableview mas_makeConstraints:^(MASConstraintMaker *make) {
33 |
34 | make.edges.equalTo(0);
35 |
36 | }];
37 |
38 | [[self rac_signalForSelector:@selector(tableView:didSelectRowAtIndexPath:) fromProtocol:@protocol(UITableViewDelegate) ] subscribeNext:^(RACTuple * x) {
39 |
40 | NSLog(@"点击了");
41 | NSLog(@"%@,%@",x.first,x.second);
42 |
43 | }];
44 |
45 | //这样子不带协议是无法代替代理的,虽然能达到效果,这个方法表示某个selector被调用时执行一段代码.带有协议参数的表示该selector实现了某个协议,所以可以用它来实现Delegate。
46 | // [[self rac_signalForSelector:@selector(tableView:didSelectRowAtIndexPath:)] subscribeNext:^(RACTuple* x) {
47 | //
48 | // NSLog(@"%@",[x class]);
49 | // NSLog(@"%@",x);
50 | // }];
51 |
52 | //这里是个坑,必须将代理最后设置,否则信号是无法订阅到的
53 | //雷纯峰大大是这样子解释的:在设置代理的时候,系统会缓存这个代理对象实现了哪些代码方法
54 | //如果将代理放在订阅信号前设置,那么当控制器成为代理时是无法缓存这个代理对象实现了哪些代码方法的
55 | tableview.delegate = self;
56 |
57 | tableview.dataSource = self;
58 |
59 | [tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
60 |
61 | }
62 |
63 | #pragma mark - 数据源方法 -
64 | -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
65 |
66 | return 1;
67 |
68 | }
69 |
70 | -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
71 |
72 | return 100;
73 | }
74 |
75 | -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
76 |
77 | UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
78 |
79 | cell.textLabel.text = @"点我";
80 |
81 | return cell;
82 |
83 | }
84 |
85 |
86 |
87 | @end
88 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/DelegateVC.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/EventVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // EventVC.h
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/25.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface EventVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/EventVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // EventVC.m
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/25.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "EventVC.h"
10 |
11 | @interface EventVC ()
12 |
13 | @end
14 |
15 | @implementation EventVC
16 |
17 | - (void)viewDidLoad {
18 | [super viewDidLoad];
19 | // Do any additional setup after loading the view from its nib.
20 |
21 | [self createupUI];
22 | }
23 |
24 | #pragma mark - UI -
25 | -(void)createupUI{
26 |
27 | UIButton * btn = [[UIButton alloc] init];
28 |
29 | [self.view addSubview:btn];
30 |
31 | [btn setTitle:@"button" forState:UIControlStateNormal];
32 |
33 | [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
34 |
35 | [btn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
36 |
37 | [btn makeConstraints:^(MASConstraintMaker *make) {
38 | make.center.equalTo(self.view);
39 | }];
40 |
41 | [[btn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
42 |
43 | NSLog(@"点击了按钮");
44 | }];
45 | }
46 |
47 |
48 |
49 | @end
50 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/EventVC.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/KVOVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // KVOVC.h
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/25.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface KVOVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/KVOVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // KVOVC.m
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/25.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "KVOVC.h"
10 |
11 | @interface KVOVC ()
12 |
13 | @end
14 |
15 | @implementation KVOVC
16 |
17 | - (void)viewDidLoad {
18 | [super viewDidLoad];
19 | // Do any additional setup after loading the view from its nib.
20 |
21 | [self createUI];
22 | }
23 |
24 | #pragma mark - UI -
25 | -(void)createUI{
26 |
27 | UIScrollView * scrollView = [[UIScrollView alloc] init];
28 |
29 | [self.view addSubview:scrollView];
30 |
31 | UIView * contentView = [[UIView alloc]init];
32 |
33 | [scrollView makeConstraints:^(MASConstraintMaker *make) {
34 | make.edges.equalTo(0);
35 |
36 | }];
37 |
38 | [scrollView addSubview:contentView];
39 |
40 | [contentView makeConstraints:^(MASConstraintMaker *make) {
41 | make.edges.equalTo(0);
42 | make.width.height.equalTo(1000);
43 | }];
44 |
45 | //代替KVO
46 | [RACObserve(scrollView, contentOffset) subscribeNext:^(id x) {
47 |
48 | NSLog(@"%@",x);
49 | }];
50 |
51 |
52 | }
53 |
54 | @end
55 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/KVOVC.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/NSNotificationVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSNotificationVC.h
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/25.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface NSNotificationVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/NSNotificationVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSNotificationVC.m
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/25.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "NSNotificationVC.h"
10 |
11 | @interface NSNotificationVC ()
12 |
13 | @property (weak, nonatomic) IBOutlet UITextField *tf;
14 | @end
15 |
16 | @implementation NSNotificationVC
17 |
18 | - (void)viewDidLoad {
19 | [super viewDidLoad];
20 | // Do any additional setup after loading the view from its nib.
21 |
22 | [self sendNotification];
23 |
24 | [self getNotification];
25 |
26 | }
27 |
28 | -(void)getNotification{
29 |
30 | //代替通知
31 | //takeUntil会接收一个signal,当signal触发后会把之前的信号释放掉
32 | [[[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIKeyboardDidShowNotification object:nil] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
33 |
34 | NSLog(@"键盘弹出");
35 |
36 | }];
37 |
38 | //这个写法有个问题,这样子写信号不会被释放,当你再次收到键盘弹出的通知时他会叠加上次的信号进行执行,并一直叠加下去,所以我们在用上面的写法
39 | // [[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIKeyboardDidShowNotification object:nil] subscribeNext:^(id x) {
40 | //
41 | // NSLog(@"键盘弹出");
42 | //
43 | // }];
44 |
45 | //这里这样写只是为了给大家开拓一种思路,selector的方法可以应需求更改,即当这个方法执行后,产生一个信号告知控制器释放掉这个订阅的信号
46 | RACSignal * deallocSignal = [self rac_signalForSelector:@selector(viewWillDisappear:)];
47 |
48 | [[[[NSNotificationCenter defaultCenter] rac_addObserverForName:@"haha" object:nil] takeUntil:deallocSignal] subscribeNext:^(id x) {
49 |
50 | NSLog(@"haha");
51 | }];
52 |
53 | }
54 |
55 | -(void)sendNotification{
56 |
57 | [[NSNotificationCenter defaultCenter] postNotificationName:@"haha" object:nil userInfo:nil];
58 | }
59 | -(void)dealloc{
60 |
61 | NSLog(@"控制器销毁");
62 | }
63 |
64 | @end
65 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/NSNotificationVC.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/PrefixHeader.pch:
--------------------------------------------------------------------------------
1 | //
2 | // PrefixHeader.pch
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/24.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #ifndef PrefixHeader_pch
10 | #define PrefixHeader_pch
11 |
12 |
13 | #import "ReactiveCocoa.h"
14 |
15 | //define this constant if you want to use Masonry without the 'mas_' prefix
16 | #define MAS_SHORTHAND
17 |
18 | //define this constant if you want to enable auto-boxing for default syntax
19 | #define MAS_SHORTHAND_GLOBALS
20 |
21 | #import "Masonry.h"
22 |
23 | // Include any system framework and library headers here that should be included in all compilation units.
24 | // You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.
25 |
26 |
27 | #endif /* PrefixHeader_pch */
28 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/TargetOfUISignalVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // TargetOfUISignalVC.h
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/26.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface TargetOfUISignalVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/TargetOfUISignalVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // TargetOfUISignalVC.m
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/26.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "TargetOfUISignalVC.h"
10 |
11 | @interface TargetOfUISignalVC ()
12 |
13 | @property (weak, nonatomic) IBOutlet UITextField *textfiled;
14 | @end
15 |
16 | @implementation TargetOfUISignalVC
17 |
18 | - (void)viewDidLoad {
19 | [super viewDidLoad];
20 | // Do any additional setup after loading the view from its nib.
21 |
22 | //输出textfiled中的数据,具体的第一篇笔记有详细讲述
23 | [[self.textfiled rac_textSignal] subscribeNext:^(id x) {
24 |
25 | NSLog(@"%@",x);
26 | }];
27 | }
28 |
29 |
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/TargetOfUISignalVC.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/TimerVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // TimerVC.h
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/26.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface TimerVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/TimerVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // TimerVC.m
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/26.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import "TimerVC.h"
10 |
11 | @interface TimerVC ()
12 |
13 | @end
14 |
15 | @implementation TimerVC
16 |
17 | - (void)viewDidLoad {
18 | [super viewDidLoad];
19 | // Do any additional setup after loading the view from its nib.
20 |
21 | // [self test1];
22 |
23 | [self test2];
24 | }
25 |
26 | -(void)test1{
27 |
28 | //五秒后执行一次
29 | [[RACScheduler mainThreadScheduler]afterDelay:5 schedule:^{
30 |
31 | NSLog(@"五秒后执行一次");
32 | }];
33 | }
34 |
35 | -(void)test2{
36 |
37 | //每隔两秒执行一次
38 | //这里要加takeUntil条件限制一下否则当控制器pop后依旧会执行
39 | [[[RACSignal interval:2 onScheduler:[RACScheduler mainThreadScheduler]] takeUntil:self.rac_willDeallocSignal ] subscribeNext:^(id x) {
40 |
41 | NSLog(@"每两秒执行一次");
42 | }];
43 | }
44 |
45 | @end
46 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/TimerVC.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/basic/the skills of RAC/the skills of RAC/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // the skills of RAC
4 | //
5 | // Created by fy on 16/8/24.
6 | // Copyright © 2016年 LY. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------