Created
May 16, 2012 17:57
-
-
Save brettkelly/2712630 to your computer and use it in GitHub Desktop.
countAllNotesAndSetTextField
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)countAllNotesAndSetTextField | |
{ | |
// Allow access to this variable within the block context below (using __block keyword) | |
__block int noteCount = 0; | |
EvernoteNoteStore *noteStore = [EvernoteNoteStore noteStore]; | |
[noteStore listNotebooksWithSuccess:^(NSArray *notebooks) { | |
for (EDAMNotebook *notebook in notebooks) { | |
if ([notebook guid]) { | |
EDAMNoteFilter *filter = [[EDAMNoteFilter alloc] init]; | |
[filter setNotebookGuid:[notebook guid]]; | |
[noteStore findNoteCountsWithFilter:filter withTrash:NO success:^(EDAMNoteCollectionCounts *counts) { | |
if (counts) { | |
// Get note count for the current notebook and add it to the displayed total | |
NSNumber *notebookCount = (NSNumber *)[[counts notebookCounts] objectForKey:[notebook guid]]; | |
noteCount = noteCount + [notebookCount intValue]; | |
NSString *noteCountString = [NSString stringWithFormat:@"%d", noteCount]; | |
[noteCountField setText:noteCountString]; | |
} | |
} failure:^(NSError *error) { | |
NSLog(@"Error while retrieving note counts: %@", error); | |
}]; | |
} | |
} | |
} failure:^(NSError *error) { | |
NSLog(@"Error while retrieving notebooks: %@", error); | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment