-
Notifications
You must be signed in to change notification settings - Fork 767
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ff0885
commit f47f15d
Showing
3 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
|
||
|
||
## 6.是否了解链式编程? | ||
|
||
##### 链式编程其实就两个要点: | ||
- Block 作为当前对象的属性。 | ||
- Block 返回值是当前对象。 | ||
|
||
|
||
|
||
|
||
##### 写个特别简单的小Demo: | ||
|
||
###### .h文件 | ||
|
||
```objc | ||
#import <UIKit/UIKit.h> | ||
|
||
@interface SecViewController : UIViewController | ||
|
||
@property (nonatomic,copy ) SecViewController *(^setUpBackGroundColor)(UIColor *color) ; | ||
|
||
@property (nonatomic,copy ) SecViewController *(^setUpTitle)(NSString *title); | ||
|
||
@end | ||
``` | ||
|
||
|
||
###### .m文件 | ||
|
||
```objc | ||
@implementation SecViewController | ||
|
||
- (SecViewController *(^)(NSString *))setUpTitle { | ||
|
||
return ^(NSString *title) { | ||
|
||
self.title = title; | ||
return self; | ||
}; | ||
} | ||
|
||
- (SecViewController *(^)(UIColor *))setUpBackGroundColor { | ||
|
||
return ^(UIColor *backColor) { | ||
|
||
self.view.backgroundColor = backColor; | ||
return self; | ||
}; | ||
} | ||
|
||
@end | ||
``` | ||
###### 外部调用 | ||
```objc | ||
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { | ||
SecViewController *sec = [SecViewController new]; | ||
sec.setUpBackGroundColor([UIColor orangeColor]).setUpTitle(@"heihei"); | ||
[self.navigationController pushViewController:sec animated:YES]; | ||
} | ||
``` | ||
|
||
|
||
如果看不懂自己敲一遍就懂了。 |