Skip to content

Instantly share code, notes, and snippets.

View acwright's full-sized avatar

Aaron Wright acwright

View GitHub Profile
@acwright
acwright / gist:1535473
Created December 29, 2011 18:34
Create dynamic date predicate using now() function
// The goal...
[NSPredicate predicateWithFormat:@"dateModified >= CAST(CAST(now(), \"NSNumber\") - %d, \"NSDate\")", (30*86400)];
//"now()" is a function and takes no arguments
NSExpression *now = [NSExpression expressionForFunction:@"now" arguments:[NSArray array]];
//CAST(now(), 'NSNumber')
NSArray *castNowArguments = [NSArray arrayWithObjects:now, [NSExpression expressionForConstantValue:@"NSNumber"], nil];
NSExpression *castNow = [NSExpression expressionForFunction:@"castObject:toType:" arguments:castNowArguments];
@acwright
acwright / gist:1163883
Created August 22, 2011 23:10
Cocoa Menu Item Title Toggle
# pragma mark menu
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
if ([menuItem action] == @selector(toggleRuler:)) {
if ([canvasView rulersVisible]) {
[menuItem setTitle:@"Hide Ruler"];
} else {
[menuItem setTitle:@"Show Ruler"];
}
}