NSExpression
The relatively new NSExpression class is incredibly powerful, yet not really gived actually often. Part of that is that its not very well documented. Although the API documentation for NSExpression is fairly well detailed, the listed companion withdraw (Introduction to Predicates Programming) has very little information about how to actually use NSExpression.
NSExpression deserves to be better documented, because it brings to predicate programming (including Core Data), a lot of f feed inures from the relational database world that people often remonstrate are missing, like unioning, intersecting, and subtracting resultsets and performing aggregate operations without load managed aspirations or faults into memory.
The aggregates functionality is especially important on iOS given the special(a) memory on most iOS devices. If youve got a large dataset, and you desire to get a count of objects, or calculate an median(a) or means for one of the attributes, you really dont desire to ease up to pull the entire dataset into memory. Even if theyre just faults, theyre going to eat up memory you dont need to use because the underlying SQLite long store can figure that stuff out without the object overhead.
I dont have time to do a dependable NSExpression tutorial, but I thought it at least price posting a category on NSManagedObject that lets you take reinforcement of some of its more useful features.
With this category, to get a sum of the attribute forfend on entity Foo, you would do this:
NSNumber *fooSum = [Foo aggregateOperation:@sum: onAttribute:@bar withPredicate:nil inManagedObjectContext:context];
This will calculate it for you using the database features, NOT by loading all the managed objects into memory. Much more memory and mainframe computer efficient than doing it manually.
Cheers. Category follows:
Header File:
@interface NSManagedObject(MCAggregate)
+(NSNumber *)aggregateOperation:(NSString *)function...If you want to get a full essay, order it on our website: Ordercustompaper.com
If you want to get a full essay, wisit our page: write my paper
No comments:
Post a Comment