1

I have a function meant for an iOS app. The NSString valueand key contain the value and key however it doesnt seem to get assign to the NSMutableDictionary data on the line [data setValue:value forKey:key]

-(NSMutableDictionary *)parseCode:(NSString *)string{
    NSArray *array = [string componentsSeparatedByString:@"||"];
    NSMutableDictionary *data;
    for(id object in array){
        NSArray *objectAndKey = [object componentsSeparatedByString:@"::"];
        NSString *key =[objectAndKey objectAtIndex:0];
        NSString *value = [objectAndKey objectAtIndex:1];
        [data setValue:value forKey:key];
        [self alertMeWithString:[data valueForKey:key]];
    }
    return data;
}
4

1 回答 1

2

你需要初始化和分配你的 NSMutableDictionary。

 NSMutableDictionary *data = [NSMutableDictionary dictionary];

或者您可以使用显式拨打电话

 NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
于 2013-07-21T12:06:15.383 回答