Search code examples
iosobjective-cormdbaccess

DBAccess: Get array of any one property value


I have dbobject like:

#import <Foundation/Foundation.h>
#import <DBAccess/DBAccess.h>

@interface GroupMember : DBObject

@property (strong) NSString *firstname;
@property (strong) NSString *lastname;
@property (strong) NSString *_id;

@end

How can I get an array of all group member's firstname?


Solution

  • Because you are not dealing with SQL but with whole objects, this requires a little bit of working round the problem, but it is possible.

    NSDictionary* resultsGroupedByFirstName = [[GroupMember query]  groupBy:@"firstname"];
    NSArray* names = resultsGroupedByFirstName.allKeys;
    

    This is a fairly expensive call as it is having to do a fair amount of work in the background. Although it is optimised slightly by using an index to detect changes in the column.

    This should do the trick.

    NOTE:

    DBAccess v1.6.7 now has a distinct call thanks to your question and feedback. http://www.db-access.org/downloads