Created
September 12, 2014 20:06
-
-
Save HeidiHansen/dc55d705cb2d95f24713 to your computer and use it in GitHub Desktop.
Extracting titles from an array of book dictionaries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
NSMutableArray *arrayOfBooks = [[NSMutableArray alloc]init]; | |
[MPSAPI getBookLibrary:^(NSArray *books) { | |
for (NSMutableDictionary *book in books) { | |
NSString *bookTitle = book[@"title"]; | |
[arrayOfBooks addObject:bookTitle]; | |
} | |
}]; | |
} | |
//associated API request: | |
+ (void)getBookLibrary:(void (^)(NSArray *))completion { | |
NSOperationQueue *backgroundqueue =[NSOperationQueue new]; | |
NSString *getURL = [NSString stringWithFormat:@"%@", kMAIN_API_URL]; | |
NSLog(@"%@", getURL); | |
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; | |
[manager GET:getURL | |
parameters:nil | |
success:^(AFHTTPRequestOperation *task, id responseObject) { | |
NSLog(@"%@", responseObject); | |
[backgroundqueue addOperationWithBlock:^{ | |
completion(responseObject); | |
}]; | |
}failure:^(AFHTTPRequestOperation *task, NSError *error) { | |
NSLog(@"Failed: %@", error.localizedDescription); | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment