Ask HN: What does Apple's new policy mean for Groupon?
2 pointsby nomurrcy0 comments
NSArray *records = [[db find:[NSDictionary dictionaryWithObject:@"Joe" forKey:@"name"] limit:10]
sortedArrayUsingComparitor:^(id a, id b) {
// sort logic
}];
I typically add a category to NSArray for mapping a selector or block. The signatures are
- (NSArray )mapBlock:(id (^)(id object))block;
- (NSArray )mapSel:(SEL)selector; NSArray *records = [[[db find:[NSDictionary dictionaryWithObject:@"Joe" forKey:@"name"]
limit:10]
sortedArrayUsingComparitor:^(id a, id b) {
// sort logic
}]
mapSel:@selector(lowercaseString)];
Also for mapping over an array you can usually use NSArrays valueForKey: which returns a new array
which contains the result of calling valueForKey: on each member of the target array.
As your sorting logic would typically exist in the db layer whether you were using CoreData or something else, it would be easy to write a wrapper such that you could write something like: [[[[MyFetchRequest forEntityNamed:@"foo"
orderedBy:@"SomeKey"
limit:10] fetch]
valueForKey@"nameField.lowerCaseString"]
enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
// do stuff here
}];
Again this is all 'fake' code as this is just a readability discussion.
99% of the time the tools provided by jetbrains / vscode are more than sufficient, but 1% of the time a tool like this saves you a bunch of time, both searching for what you need to change and making the changes you want.