Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
927 views
in Technique[技术] by (71.8m points)

iphone - Empty NSMutableArray , not sure why

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...