I have one NSMutableArray with two fields: name and number. The Name of Array is "Urgency" and it contains :
urgency: "ADMIT",
urgencyId: 5
My question is how can I add only the urgency into the temp array? I dont want to add the urgencyID.
I have one NSMutableArray with two fields: name and number. The Name of Array is "Urgency" and it contains :
urgency: "ADMIT",
urgencyId: 5
My question is how can I add only the urgency into the temp array? I dont want to add the urgencyID.
It looks like an NSDictionary or your array contains objects of dictionary with two keys called urgency and urgencyId.
You can get it by [... valueForKey:@"urgency"]
EDIT:
I think this (I tried to replicate what you are saying ) may come helpful for you:
NSString *keyUrgency = @"urgency";
NSString *keyUrgencyId = @"urgencyId";
NSDictionary *u1 = @{keyUrgency: @"u1_urgency",
keyUrgencyId: @"u1 id"};
NSDictionary *u2 = @{keyUrgency: @"u2_urgency",
keyUrgencyId: @"u2 id"};
NSDictionary *u3 = @{keyUrgency: @"u3_urgency",
keyUrgencyId: @"u3 id"};
NSArray *array = @[u1, u2, u3];
NSLog(@"array : %@",array);
//you want only urgencies in array
NSArray *urgencies = [array valueForKey:keyUrgency];
NSLog(@"urgencies : %@",urgencies);
You can hold all values like this in one array.
NSArray *allUrgency = [dict valueForKeyPath:@"urgency"];
valueForKeyPath:returns id not the NSString@"key.urgencyYou can do like follow and that is from : iOS - Make a copy of a array object into another
NSMutableArray *tmp = [[NSMutableArray alloc] init];
for(NSArray *dim1Array in yourMultidimensionalArray)
{
for(id obj in dim1Array)
{
if([obj valueForKey:@"urgency"])
{
[tmp addObject:dim1Array];
break; // I assume you only want to add it once
}
}
}