Frank Frank - 5 months ago 9
Objective-C Question

Property 'levelCompleted' not found on object of type 'id'

Here's my model class

LevelInformationModel
.

@interface LevelInformationModel : NSObject

@property NSInteger levelCompleted;
+(id)sharedModel;

@end


#import "LevelInformationModel.h"

@implementation LevelInformationModel

@synthesize levelCompleted;

/* Return singleton model */
+ (id)sharedModel {
static LevelInformationModel *sharedModel = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedModel = [[self alloc] init];
});
return sharedModel;
}

- (id)init {
self = [super init];
if (self) {
self.levelCompleted = 0;
}
return self;
}

@end


And here's how I'm using it all (in
GameViewController
class). I have imported
LevelInformationModel.h
already.

NSInteger currentLevel = [LevelInformationModel sharedModel].levelCompleted;


But above the
levelCompleted
property is the error
Property 'levelCompleted
not found on type 'id'`. Any thoughts would be great.

Answer

That's because your method is returning an id.

Change it to this

+(LevelInformationModel)sharedModel 
{
.