enumerateKeysAndObjectsUsingBlock
NSDictionary有一个方法叫enumerateKeysAndObjectsUsingBlock,
它就一个参数就是block,这个block携带了三个参数,这将要把dictionary里面的key和value每次一组传递到block,enumerateKeysAndObjectsUsingBlock会遍历dictionary并把里面所有的key和value一组一组的展示给你,每组都会执行这个block。
下面展示一些 内联代码片
。
if([result[@"words_result"] isKindOfClass:[NSDictionary class]]){
[result[@"words_result"] enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
if([obj isKindOfClass:[NSDictionary class]] && [obj objectForKey:@"words"]){
[message appendFormat:@"%@:%@\n", key, obj[@"words"]];
}else{
[message appendFormat:@"%@:%@\n", key, obj];
}
}];
}
if([result[@"words_result"] isKindOfClass:[NSDictionary class]]){
[result[@"words_result"] enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
if([obj isKindOfClass:[NSDictionary class]] && [obj objectForKey:@"words"]){
[message appendFormat:@"%@:%@\n", key, obj[@"words"]];
}else{
[message appendFormat:@"%@:%@\n", key, obj];
}
}];
}