#import <Foundation/Foundation.h>
@interface ClassA : NSObject
@end
@interface ClassB : NSObject
- (id)initWithString:(NSString *)str;
@end
#import "ClassA.h"
@class ClassB;
@interface ClassA ()
@property (nonatomic, readonly)ClassA *(^aaa)(BOOL eblne);
@property (nonatomic, readonly)ClassA *(^bbb)(NSString * str);
@property (nonatomic, readonly)ClassB *(^ccc)(NSString * str);
@end
@implementation ClassA
- (ClassA *(^)(BOOL))aaa
{
return ^(BOOL eblne){
if (eblne) {
NSLog(@" is YES");
}else
{
NSLog(@" is NO");
}
return self;
};
}
- (ClassA *(^)(NSString *str))bbb
{
return ^(NSString * str){
NSLog(@"str:%@", str);
return self;
};
}
// 这里返回了ClassB的一个实例,于是后面就可以继续链式 ClassB 的 block 方法
// 见下面例子 .ccc(@"Objective-C").ddd(NO)
- (ClassB *(^)(NSString * str))ccc
{
return ^(NSString *str) {
//code
NSLog(@"b %@", str);
ClassB * b = [[ClassB alloc] initWithString:str];
return b;
};
}
@end
@interface ClassB ()
@property(nonatomic, readonly)ClassB*(^ddd)(BOOL eblne);
@end
@implementation ClassB
- (id)initWithString:(NSString *)str
{
return self;
}
- (ClassB*(^)(BOOL eblne))ddd
{
return ^(BOOL eblne){
if (eblne)
{
NSLog(@"classB yes");
}else
{
NSLog(@"classB no");
}
return self;
};
}
// 最后我们可以这样做
//id a = [ClassA new];
//a.aaa(YES).bbb(@"HelloWorld!").ccc(@"Objective-C").ddd(NO);