Creating an advanced NSPredicateEditorRowTemplate
In a recent post I covered how to make a simple NSPredicateEditorRowTemplate. In this post we’re going to go a bit deeper. The Setup In our last example, we did some simple date comparisons, where we were comparing an NSTimeInterval against a property that represented a duration. For example, if we had an array of Song objects, then we could use that row template to construct a...
Mathematically evaluating NSStrings
I’ve recently posted the code to a project I’ve written called DDMathParser. It’s a way whereby you can take an NSString and evaluate it as a mathematical expression. For example, you can do: NSLog(@"%@", [@"1 + 3 * 4 - 5" numberByEvaluatingString]); //logs "8" There are several other ways to evaluate strings, including methods that allow you to use variables (1 + $a, and...
Creating a simple NSPredicateEditorRowTemplate
NSPredicateEditor is a great class, provided you figure out how it works. There’s a fair amount of documentation as to what’s going on, but if you ever want to do something beyond what’s possible through configuration in Interface Builder, you’re probably going to spend several hours playing with things until you get it right. Hopefully, I can help cut down that...
NSPredicate is a nifty class. It’s intended use is to be an objected-oriented way of expressing a truth statement. We see this being used with things like -[NSArray filteredArrayUsingPredicate:], -[NSFetchRequest setPredicate:], and more. NSPredicate, however, can offer us a lot more. There are 2 things that make NSPredicate so insanely awesome: Its string parser The evaluation power...
Defining custom key path operators
(This was prompted by a recent question on StackOverflow.) Key-value coding is one of my more favorite things about Cocoa (up there with NSPredicate). Basically, it allows you to access properties of objects by name (ie, as a string) rather than invoking a method (er… sending a message) directly. Along with accessing properties, you can (with some limitations) retrieve calculated values...
Mike Ash: Creating Classes at Runtime →
Another great article by Mike Ash that’s an expansion on my earlier article about dynamic subclassing.
Followup to Localizing NSPredicateEditor
To expand a little bit on my previous post, here’s a little bit more information: If you ever forget the format to put in the NSLocalizedString() macros, you can do the following: predicateEditor = ... //an NSPredicateEditor NSData * stringsData = [predicateEditor _generateFormattingDictionaryStringsFile]; NSString * strings = [[NSString alloc] initWithData:stringsData...
Many people who know me personally (at least as a developer), know something interesting about me: I love NSPredicate. I love it so much that I stood up and blathered for an hour on how awesome it is. I won’t go into that here. One of the things that make NSPredicate superbly awesome is the NSPredicateEditor. NSPredicateEditor, in a nutshell, is a way to visually build an NSPredicate,...