2013-07-21 2 views
1

iOS 앱용 기능이 있습니다. 있는 NSString valuekey 그러나 [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; 
} 
+2

초급 실수를 사용하여 전화를 걸 수 있습니다. 대부분의 다른 언어와 달리 Objective-C에서는 nil 포인터를 호출해도 오류가 발생하지 않지만 단순히 0/nil을 반환합니다. –

+0

관련 항목 : [NSMutableDictionary에서 setObject : forKey :와 setValue : forKey :의 차이점은 무엇입니까?] (0120-385-305) – dasblinkenlight

답변

2

당신은 초기화하고 NSMutableDictionary를 할당하는 데 필요한 행에 NSMutableDictionary data에 할당받을 것 같지 않습니다 가치와 키가 포함되어 있습니다.

NSMutableDictionary *data = [NSMutableDictionary dictionary]; 

또는 명시 적으로

NSMutableDictionary *data = [[NSMutableDictionary alloc] init]; 
+1

문제 감사했습니다! 아마추어 오류. –