Empty NSMutableArray , not sure why

前端 未结 4 1668
醉酒成梦
醉酒成梦 2020-12-20 09:42

Ok so I populate the array like this:

NSMutableArray *participants;
for(int i = 0; i < sizeofpm; i++){
        NSDictionary *pmpart_dict = [pm_participant         


        
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-20 10:15

    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
    }
    

提交回复
热议问题