Objective C的内联函数,既有趣又快速。
pod "ObjectiveCInlines", "~> 0.1.0"
NSArray
#import <ObjectiveCInlines/NSArrayInlines.h>
NSArrayEach(arr, ^(id obj) {
});
NSArrayMap(arr, ^id*(id obj) {
return obj;
});
NSArrayReduce(arr, memo, ^id(id memo, id obj) {
return memo;
});
NSArrayFind(numsArr, ^bool(id obj) {
return true;
});
NSDictionary
#import <ObjectiveCInlines/NSDictionaryInlines.h>
NSDictionaryEach(dict, ^(NSString *key, id obj) {
});
NSDictionaryMap(dict, ^id(NSString *key, id obj) {
return obj;
});
NSJSON
#import <ObjectiveCInlines/NSJSONInlines.h>
NSJSONObjectWithData(stringDictData, NSJSONReadingAllowFragments, nil);
NSJSONDataWithObject(stringDict, NSJSONWritingPrettyPrinted, nil);
NSJSONStringWithObject(dict, NSJSONWritingPrettyPrinted, nil);
NSJSONObjectWithString(@"{}", NSJSONReadingAllowFragments, nil);
GCDAsync
#import <ObjectiveCInlines/GCDInlines.h>
GCDAsync(^{
// background
});
GCDAsyncMain(^{
// main thread
});