I have a couple questions about how to best find entries so that a plugin can use or process them.
1. How can I find (get a pointer to) an entry if I have it's path? e.g. root/mGTD/Archive/archiveFile
2. How can I find all entries with any value for "dueDate"
3. all entries with the "customData" column containing the string @"test".
thanks,
Jeff
EDIT: just to clarify: in the first example I would indeed be looking for an entry, but in the second two, I assume that it would instead be entryData objects that would be returned.
1. How can I find (get a
1. How can I find (get a pointer to) an entry if I have it's path? e.g. root/mGTD/Archive/archiveFile
What are you going to use this for? If you are trying to store a reference to an entry it's better to use entry ID's. Anyway to get the entry for a path you'll need to do a manual search. Start with the root entry and iterator over its children looking for a child that matches the first path element name, and continue that process for the found child until you have processed all path elements.
2. How can I find all entries with any value for "dueDate"
You'll need to use CoreData. Here's how to setup a fetch and get the results. If you want to display a live fetchRequest in the entries view you'll also need to look at MIEntryLiveFetchRequestProtocol, but I don't think that's what you are asking. I haven't run this code, but assuming I copied everything correctly that is what you need to get all Entries that have a dueDate set.
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"entryData.dueDate != nil"];
NSManagedObjectContext *managedObjectContext = [moriDocument managedObjectContext];
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
NSError *fetchError = nil;
NSArray *fetchResults = nil;
@try {
[fetchRequest setEntity:[NSEntityDescription entityForName:@"Entry" inManagedObjectContext:managedObjectContext]];
[fetchRequest setPredicate:predicate];
fetchResults = [managedObjectContext executeFetchRequest:fetchRequest error:&fetchError];
} @catch (NSException *e) {
logErrorWithException(@"failed executeFetchRequest", e);
}
3. all entries with the "customData" column containing the string @"test".
You'll also need to use CoreData for this. Use the above code, but change the predicate to:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"entryData.customData contains %@", @"test"];
or
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"entryData.customData like %@", @"*test*"];
I'm not entirely sure about difference is between the like and contains predicates in this case. I have the impression that contains is faster, but it also doens't seem to work in some cases. Like always seems to work.