我不明白我做错了什么。我有一本字典作为一个单独的类的属性:Objective C/NSMutableDictionary - [NSCFSet objectForKey:]:无法识别的选择器
@interface CABResourceManager : NSObject
{
....
NSMutableDictionary* soundMap;
}
@property (retain) NSMutableDictionary *soundMap;
然后我对象添加到这个字典中的一类方法:
+ (void)loadSoundFromInfo:(ABSoundInfo)sound
{
static unsigned int currentSoundID = 0;
CABSound* newSound = [[CABSound alloc] initWithInfo:(ABSoundInfo)sound soundID:++currentSoundID];
[[CABResourceManager sharedResMgr].soundMap setObject:newSound forKey:sound.name];
}
,并得到它的另一种方法:
+ (ALuint)playSoundByName:(NSString*)name
{
NSMutableDictionary* map = [CABResourceManager sharedResMgr].soundMap;
CABSound *sound = [map objectForKey:name]; // here comes the exception
并且应用程序退出异常。
2011-03-27 20:46:53.943 Book3HD-EN[5485:207] *** -[NSCFSet objectForKey:]: unrecognized selector sent to instance 0x226950
2011-03-27 20:46:53.945 Book3HD-EN[5485:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException'
我想这可能与内存管理的东西,但票数它看起来清楚我:CABSound对象做的setObject(),它不应该在这个时候公布保留在字典。