我正在使用被包含的方法來返回一個NSMutableDictionary的指針,它包含在一個NSArray中。但是,NSMutableArray(theOne)被創建爲不可互換的NSDictionary。這是一個問題,因爲我想用這種方法檢索後修改字典。Objective-C方法返回NSDictionary而不是NSMutableDictionary。爲什麼?
- (NSMutableDictionary*)getMatFromBoutKey:(NSString*) boutKey
{
/*
* Returns the mat object with the provided boutKey.
* Returns nil if no mat has that boutKey.
*/
NSUInteger idx = [[event objectForKey:@"mats"] indexOfObjectPassingTest:
^BOOL (NSMutableDictionary* obj, NSUInteger idx, BOOL *stop)
{
return [[obj objectForKey:@"boutKey"] isEqualToString:boutKey];
}];
if (idx == NSNotFound)
return nil;
else {
NSMutableDictionary* theOne = [[event objectForKey:@"mats"] objectAtIndex: idx];
return theOne;
}
}
這裏的調試器的圖像停在右後theOne第一次被引用斷點。
爲什麼不是theOne可變的?我如何返回一個指向NSMutableDictionary的指針,以便在得到返回的值之後我可以修改它?
謝謝!
是[event objectForKey:@「mats」]一個可變字典數組? – Selkie 2012-08-10 02:41:51
什麼是事件?那來自哪裏? – rdelmar 2012-08-10 02:42:11
不要用'get'前綴方法。這應該只是'matFromBoutKey:'。 – bbum 2012-08-10 02:54:40