osx - Objective C singleton class members -
this mac os x app. have created singleton class, i'm not sure how add class members (not sure if correct term). getting error property 'chorddictionary' not found on object of type '__strong id'
, i'm not sure why. want create nsdictionary can access via class. here's code:
#import "chordtype.h" @interface chordtype() @property nsdictionary *chorddictionary; @end @implementation chordtype + (instancetype)sharedchorddata { static id sharedinstance = nil; static dispatch_once_t oncetoken; dispatch_once(&oncetoken, ^{ sharedinstance = [[self alloc] init]; sharedinstance.chorddictionary = @{@"" : @"047", @"m" : @"037", @"dim" : @"036", @"aug" : @"048",}; //error on line }); return sharedinstance; } @end
declare sharedinstance
chordtype *
instead of id
or call setchorddictionary:
method instead of using property syntax. can't use property syntax on variables of type id
.
either:
static chordtype *sharedinstance = nil;
or:
[sharedinstance setchorddictionary:@{@"" : @"047", @"m" : @"037", @"dim" : @"036", @"aug" : @"048"}];
Comments
Post a Comment