我正在利用可可2D框架来编码目标C,我有一个用于多重目的的单一吨。 一个新目的就是获取和确定描述的“状态”。 我最近为此做了一个NSDictionary,但我对冻结方案有问题,因为采用单一州的方法。
这里有单州法典。 仅剩下一只字体:
<>h
@interface ExGlobal : NSObject {
NSArray *charStates_keys;
NSArray *charStates_objects;
NSMutableDictionary *charStates;
}
@property(nonatomic, retain) NSMutableDictionary *charStates;
+(ExGlobal*)sharedSingleton;
- (NSString *)charState:(NSString *)charName;
- (void)set_charState:(NSString *)value forCharName:(NSString *)charName;
@end
<>
#import "ExGlobal.h"
@implementation ExGlobal
@synthesize charStates;
static ExGlobal* _sharedSingleton = nil;
+(ExGlobal*)sharedSingleton {
@synchronized([ExGlobal class]) {
if (!_sharedSingleton) {
[[self alloc] init];
}
return _sharedSingleton;
}
return nil;
}
+(id)alloc {
@synchronized([ExGlobal class]) {
NSAssert(_sharedSingleton == nil, @"Attempted to allocate a second instance of a singleton.");
_sharedSingleton = [super alloc];
return _sharedSingleton;
}
return nil;
}
-(id)init {
self = [super init];
if (self != nil) {
// initialize stuff here
exitName = @"ruinsSkyMid";
sceneChangeKind = @"reborn";
charStates = [[NSMutableDictionary alloc] init];
charStates_keys = [NSArray arrayWithObjects:@"Feathers", @"Hummus", nil];
charStates_objects = [NSArray arrayWithObjects:@"at wall", @"with Feathers", nil];
charStates = [NSMutableDictionary dictionaryWithObjects:charStates_objects forKeys:charStates_keys];
}
return self;
}
- (NSString *)charState:(NSString *)charName{
NSString *value = [charStates objectForKey:charName];
return value;
}
- (void)set_charState:(NSString *)charState forCharName:(NSString *)charName{
[charStates setObject:charState forKey:charName];
}
- (void)dealloc {
//I know it doesn t get called, but just in case
[charStates release];
[super dealloc];
}
@end
对我来说,问题究竟是什么时候冻结了。 当发生这种情况时,我来到奥列里的就是:
Program received signal: “EXC_BAD_ACCESS”.
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.5 (8L1)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
Previous frame inner to this frame (gdb could not unwind past this frame)
Previous frame inner to this frame (gdb could not unwind past this frame)
我肯定不会帮助找到这一问题。 我发现,如果我重新界定了沙尔邦内部的key子、char子和char子,并制定了“查尔邦”方法,那么,除了“查尔邦”没有改变国家的情况外,它似乎没有冻结。