I currently make many calls to an SQL database to get sums of data, however the data is already in an NSArray so I would rather do my calculations on this instead.
I currently use this query on the SQL Database:
SELECT MAX(pk), pk, CASE WHEN result IS NULL THEN BFNeeded ELSE CFNeeded END AS Carry,
CASE WHEN result IS NULL THEN 1 ELSE 0 END AS Settle FROM table1;
I have a custom object that has several NSStrings the same as the SQL table (pk, BFNeeded, CFNeeded etc..) and I have several of these objects in an NSArray.
How can I perform the above query on the array?
Is there a way to perform SQL queries like above, or do I need to take a totally different approach to do the CASE?
Thanks
Check out Key Value Coding operators, which may accommodate the type of operations on an array that you are seeking:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/KeyValueCoding/Articles/CollectionOperators.html#
You may seek to filter or predicate your array, for example, you can iterate an array with a block or obtain a subset of objects that meet certain criteria or pass a test, for example with:
NSArray *filteredArray = [myArray filteredArrayUsingPredicate:myPredicate];
Then use a KVC operator for a calculation on the result set.