我正在使用被包含的方法来返回一个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