Skip to content

Instantly share code, notes, and snippets.

@AlanQuatermain
Created September 12, 2011 21:42
Show Gist options
  • Save AlanQuatermain/1212544 to your computer and use it in GitHub Desktop.
Save AlanQuatermain/1212544 to your computer and use it in GitHub Desktop.
NSDictionary * args = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithDouble: self.pageRange.start], @"START", [NSNumber numberWithDouble: self.pageRange.end], @"END", self.contentItem.contentID, @"CONTENT_ID", [self.chapterInfo.destinationURL path], @"FILE_NAME", nil];
static NSPredicate * template = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
template = [[NSPredicate predicateWithFormat: @"(pageStartPercent BETWEEN {$START, $END} OR pageEndPercent BETWEEN {$START, $END}) AND SUBQUERY(chapter, $chapter, $chapter.contentID == $CONTENT_ID AND $chapter.chapterFileName == $FILE_NAME).@count > 0"] retain];
});
[myFetchRequest setPredicate: [template predicateWithSubstitutionVariables: args]];
/*
(gdb) po template
(pageStartPercent BETWEEN {$START, $END} OR pageEndPercent BETWEEN {$START, $END}) AND SUBQUERY(chapter, $chapter, $chapter.contentID == $CONTENT_ID AND $chapter.chapterFileName == $FILE_NAME).@count > 0
(gdb) po args
{
"CONTENT_ID" = "99e6268c-362e-4e99-b37a-5a50e848dfd4";
END = "0.08333333333333333";
"FILE_NAME" = "/OEBPS/003-itr.html";
START = 0;
}
(gdb) po [req predicate]
(pageStartPercent BETWEEN {0, 0.08333333333333333} OR pageEndPercent BETWEEN {0, 0.08333333333333333}) AND SUBQUERY(chapter, $chapter, $chapter.contentID == $CONTENT_ID AND $chapter.chapterFileName == $FILE_NAME).@count > 0
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment