- (NSString*) generate:(NSArray*)data withBlock:(BOOL (^)(NSString*))aBlock;{
NSMutableString* str= [NSMutableString string];
for(NSString *v in data){
if(aBlock(v)){
[str appendString:v];
}
}
}
麻烦请教哈,这段代码是什么意思?
block bject-c
------解决方案--------------------
^是block块,这个函数是让你传入块的行为规则进去
如: NSArray *arry=[[NSArray alloc] initWithObjects:@"a",@"b",@"c",nil];
[self generate:arry withBlock:^BOOL(NSString *a) { return [a isEqualToString:@"a"];//此处行为规则你可以动态传进去
}];
这样只有“a"会加到?str里