Skip to content

Instantly share code, notes, and snippets.

@sstadelman
Created November 5, 2014 21:27
Show Gist options
  • Select an option

  • Save sstadelman/b5a4e90ccb32a707f04f to your computer and use it in GitHub Desktop.

Select an option

Save sstadelman/b5a4e90ccb32a707f04f to your computer and use it in GitHub Desktop.
[online] filtering entities when $filter not supported by back end
-(void)fetchContactsWithCompletion:(void(^)(NSArray *entities))completion {
NSString *resourcePath = @"ContactCollection;
[self scheduleRequestForResource:resourcePath withMode:SODataRequestModeRead withEntity:nil withCompletion:^(NSArray *entities, id<SODataRequestExecution> requestExecution, NSError *error) {
if (entities) {
NSMutableArray *completeEntities = [[NSMutableArray alloc] init];
[entities enumerateObjectsUsingBlock:^(id<SODataEntity> obj, NSUInteger idx, BOOL *stop) {
NSDictionary *properties = (id<SODataEntity>)obj.properties;
NSString *company = (NSString *)[(id<SODataProperty>)properties[@"company"] value];
NSString *function = (NSString *)[(id<SODataProperty>)properties[@"function"] value];
if (company.length > 0 && function.length > 0) {
[completeEntities addObject:obj];
}
}];
completion(completeEntities);
} else {
NSLog(@"did not get any entities, with error: %@", error);
}
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment