我有一个适用于iOS应用的功能。 NSString value
和key
包含值和键,但它似乎无法分配到data
行上的NSMutableDictionary [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;
}
答案 0 :(得分:2)
您需要初始化并分配NSMutableDictionary。
NSMutableDictionary *data = [NSMutableDictionary dictionary];
或者您可以使用
明确拨打电话 NSMutableDictionary *data = [[NSMutableDictionary alloc] init];