我不明白我做錯了什麼。我有一本字典作爲一個單獨的類的屬性: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(),它不應該在這個時候公佈保留在字典。