Chain.h
@interface Chain : NSObject
@property (nonatomic, assign) NSUInteger age;
@property (nonatomic, copy ) NSString *name;
+(Chain *(^)())obj;
-(Chain *(^)(NSUInteger))setAge;
-(Chain *(^)(NSString *))setName;
Chain.m
@implementation Chain
+(Chain *(^)())obj {
return ^Chain *() {
return [Chain new];
};
}
-(Chain *(^)(NSUInteger))setAge {
return ^Chain *(NSUInteger age) {
self.age = age;
return self;
};
}
-(Chain *(^)(NSString *))setName {
return ^Chain *(NSString *name) {
self.name = name;
return self;
};
}
@end
使用方法:
ViewController.m
//设值
Chain *obj = Chain.obj().setName(@"Georege").setAge(25);
//取值
NSLog(@"name:%@\nage:%lu", obj.name, obj.age);