2011-04-24 4 views
1

사전 항목의 NSMutableArray (즉, "stories")가 있습니다.사전 객체의 NSMutableArray 업데이트

배열의 사전 항목을 읽을 수 있습니다 (예 :

[[[stories objectAtIndex: b] objectForKey: @"title"] 

하지만 이제는 몇 가지 개체를 업데이트 (예 : 대체)하려고합니다. "title"& "matchingword"이지만 올바른 코드를 찾을 수 없습니다. 어떤 제안이라도 대단히 감사합니다.

나는이 시도하지만, 나는 또한 (하나지만 작동하지 않았다)이 시도

NSMutableDictionary *itemAtIndex = [[NSMutableDictionary alloc]init]; 
[itemAtIndex setObject:[[placesArray objectAtIndex:a]objectAtIndex:0] forKey:@"reference"]; 
[stories replaceObjectAtIndex:x withObject:itemAtIndex]; // replace "reference" with user's unique key 
[itemAtIndex release]; 

배열에 완전히 새로운 개체를 추가 할 것 같다

//NSMutableDictionary *itemAtIndex2 = [[NSMutableDictionary alloc]init]; 
//[itemAtIndex2 setObject:[separatePlaces objectAtIndex:x] forKey:@"matchingword"]; 
//[stories insertObject:itemAtIndex2 atIndex:x]; // add the unique matching word to story 
//[itemAtIndex2 release]; 

도움말 감사합니다. 감사.

답변

2

수정하려는 사전을 가져와야합니다.

NSMutableDictionary *temp = [stories objectAtIndex: b]; 

의 변화 값 :

[temp setObject:@"new Info" forKey:@"title"]; 
+0

감사합니다. 그것은 좀 더 복잡한 것으로 판명되었습니다. 이해가 안되는 이유 때문에 위의 코드는 런타임에 오류 개체를 변경하려고한다는 오류가 발생했습니다. 나는 점검했고 배열의 모든 것은 변경 가능했다. 그래서 나는 덧붙였다 : tempDict = [[stories objectsAtIndex : b] mutableCopy]; 개체를 업데이트했지만 첫 번째 사전에 저장하지 않으므로 결과가 새 사전에 복사됩니다. 이것은 잘 작동합니다. 감사. – Jeremy

관련 문제