0

Ok so I populate the array like this:

NSMutableArray *participants;
for(int i = 0; i < sizeofpm; i++){
 NSDictionary *pmpart_dict = [pm_participants objectAtIndex:i];
 NSString *pmpart_email = [pmpart_dict objectForKey:@"email"];
 NSString *pmpart_email_extra = [@"pm" stringByAppendingString:pmpart_email];
 [participants setValue:pmpart_email forKey:pmpart_email_extra];
 NSLog(@"%@", participants);
 } 

sizeofpm is 1. that is using count. to get the number of values in the array. How can i store values to that array? It doesnt seem to be working. Thanks!

asked Jul 24, 2012 at 13:49

4 Answers 4

2

you need to alloc it first. Try to change the first line to:

NSMutableArray* participants = [[NSMutableArray alloc] init];

also using setValue:forKey: wont work with an NSMutableArray as an array has no key.

Try using [participants addObject:pmpart_email];.

answered Jul 24, 2012 at 13:51

1 Comment

I missed that, you missed the setValue:! Between us, we've got it covered.
2

You don't create the array, you just declare it.

NSMutableArray *participants = [NSMutableArray array];

After that, setValue:forKey: will not add objects to an array. You need addObject::

[participants addObject:pmpart_email];

There is no key.

answered Jul 24, 2012 at 13:51

Comments

1

You are assigning a value to an NSMutableArray *participants like how you assign values to an NSDictionary object. To assign values to NSMutableArray you can call - (void)addObject:(id)anObject

answered Jul 24, 2012 at 13:54

Comments

0

So, I as some of the other answer have stated, you're missing your initializer for participants. However, judging by your use of setValue:forKey:, and how you appear to be structuring your data, you're not looking for NSMutableArray, but instead NSMutableDictionary. Arrays are simply lists, whereas dictionaries maintain key-value relationships, which you appear to be attempting to leverage.

Try this:

// some classes provide shorthand for `alloc/init`, such as `dictionary`
NSMutableDictionary *participants = [NSMutableDictionary dictionary];
for(int i = 0; i < sizeofpm; i++){
 NSDictionary *pmpart_dict = [pm_participants objectAtIndex:i];
 NSString *pmpart_email = [pmpart_dict objectForKey:@"email"];
 NSString *pmpart_email_extra = [@"pm" stringByAppendingString:pmpart_email];
 [participants setValue:pmpart_email forKey:pmpart_email_extra];
 NSLog(@"%@", participants);
} 

This will give you a dictionary in the form of

{
 pmpart_email_extra: pmpart_email
}
answered Jul 24, 2012 at 13:58

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.