-1

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.

4
  • 2
    is it nsmutablearray or nsmutabledictionary? Commented Dec 4, 2013 at 12:33
  • You haven't really explained your problem or your data structure very clearly. Post the code you have so far, it might speak for you Commented Dec 4, 2013 at 12:36
  • possible duplicate of copy NSArray inside an empty NSArray Commented Dec 4, 2013 at 13:05
  • Hi Firdos it is nsmutableaarry Commented Dec 16, 2013 at 12:56

3 Answers 3

0

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);
Sign up to request clarification or add additional context in comments.

9 Comments

but how can i get all the "urgency " only there 20 urgency's ?
this will return array.
Hi Anoop can please write exactly into the code format i did same but not get success
as bhargavi answers say.
Thats right Anoop but all my values are all ready stored into one nsmutable array in that array these two things are there out of that i need only "urgency" into the other string array
|
0

You can hold all values like this in one array.

NSArray *allUrgency = [dict valueForKeyPath:@"urgency"];

5 Comments

If the array contains NSDictionary the result for [dict valueForKeyPath:@"urgency"]; it's NSString not NSArray.
valueForKeyPath:returns id not the NSString
Yes, I agree but for the scenario above urgency: "ADMIT" it's string.
Hi Bhargavi thanx for reply ,But how can i get all the urgency and what is the "dict"?
KeyPath must have a dot in between isnt'it, like @"key.urgency
0

You 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
       }
    }
 }

2 Comments

Application is crash :(
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Urgency countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.