Kuldeepsingh Rajput Kuldeepsingh Rajput - 1 year ago 54
Objective-C Question

How to copy particular array objects from one array to another array?

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.

Answer Source

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"]


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);