How to call a non-stationary method from a static method in object c?

I have a class in which I am using a singleton pattern.I have a static method. Now I want to call a non-stationary method inside a static method. But I can’t name him. Please tell me what the solution is.

#import "ThemeManager.h" @implementation ThemeManager +(ThemeManager *)sharedInstance { NSLog(@"shared instance called"); static ThemeManager *sharedInstance = nil; if (sharedInstance == nil) { sharedInstance = [[ThemeManager alloc] init]; } [self getPref];//i get error at this line return sharedInstance; } -(void)getPref { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *themeName = [defaults objectForKey:@"theme"] ?: @"default"; NSLog(@"theme name is %@",themeName); NSString *path = [[NSBundle mainBundle] pathForResource:themeName ofType:@"plist"]; self.theme = [NSDictionary dictionaryWithContentsOfFile:path]; } @end 
0
source share
1 answer
 [sharedInstance getPref] 

non-stationary methods are instance methods. the receiver must be an instance. in your case, the instance you want to use is, of course, the sharedInstance that you just created.

inside a class, the method itself is the class itself. why you get an error in this line, because self is not an instance in this context.

+6
source

Source: https://habr.com/ru/post/1412603/


All Articles