[RootModel setAppLevel:]: unrecognized selector sent to instance
I have a class called RootModel. In RootModel.h I have:
@interface RootModel : NSObject {
NSString *appLevel;
}
@property(nonatomic, retain) NSString *appLevel;
In RootModel.m I have the following:
#import "RootModel.h"
#import "MainViewController.h"
@implementation RootModel
@synthesize appLevel;
#pragma mark Singleton Methods
static RootModel *sharedObject = nil;
+(id)sharedModel {
@synchronized(self){
if(sharedObject == nil)
sharedObject = [[super allocWithZone:NULL] 开发者_JS百科init];
}
return sharedObject;
}
in MainViewController.m I have:
RootModel *rm = [RootModel sharedModel];
rm.appLevel = @"0";
The last statement give me [RootModel setAppLevel:]: unrecognized selector sent to instance. It should be noted that everything was working fine with the above code. My project somehow got corrupted and I built a new project using the files and now I get this error. Thanks for any help.
in RootModel.h
@class MainViewController;//note Here
@interface RootModel : NSObject {
NSString *appLevel;
}
@property(nonatomic, retain) NSString *appLevel;
+(id)sharedModel;//Note Here
@end
You may have forgotten this method
+ (id)allocWithZone:(NSZone *)zone {
return [[self sharedManager] retain];
}
Take a look at this.
精彩评论