I have a fetch that returns an array with dictionary in it of an attribute of a core data object.
Here is my previous question: Create Array From Attribute of NSObject F
Call valueForKey on the array object returned from the fetch request. That will in-turn call valueForKey
on each object and return an array of all resulting values.
NSArray *timestamps = [objects valueForKey:@"timeStamp"];
The Fast Enumeration method:
NSMutableArray *data = [[NSMutableArray alloc] initWithCapacity:array.count];
for (NSDictionary *d in objects) {
[data addObject:[d objectForKey:@"timeStamp"]];
}
The Block enumerator method:
NSMutableArray *data = [[NSMutableArray alloc] initWithCapacity:array.count];
[objects enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[data addObject:[obj objectForKey:@"timeStamp"]];
}];
Either way, 'data' contains just an array of NSDate instances.
To get the type of array you want, you can do something like this:
NSMutableArray *array = [[NSMutableArray alloc] init];
for (int n = 0; n < [data count]; n++) // data array
{
NSMutableArray *array = [[NSMutableArray alloc] init];
array = [NSMutableArray arrayWithObjects:[[data objectAtIndex:n] valueForKey:@"timeStamp"] ,nil];
if ([array count] != 0) {
[newArray addObject:[array objectAtIndex:0]];
}
}
[array release];
hope this will help you!!
~Manoj