내 앱에서 싱글 톤 클래스를 구현하려고합니다.objective c 싱글 톤 공유 인스턴스가 호출되지 않음
[myAppManager sharedManager];
를 따를 때 내가 didFinishLaunchingWithOptions에 AppDelegate에에서 sharedManager를 호출 할 때
Appmanager.h
#import <Foundation/Foundation.h>
@interface myAppManager : NSObject{
}
+ (id)sharedManager;
-(void)storeData;
@end
Appmanager.m 이제
#import "myAppManager.h"
@implementation myAppManager
+ (id)sharedManager {
static myAppManager *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
}
- (id)init {
if (self = [super init]) {
}
return self;
}
-(void)storeData{
NSLog(@"store data called");
}
@end
을 따를 내 sharedInstance입니다3210
sharedInstance 메서드를 호출하지 않고 디버깅 지점을 사용하려고했지만 호출하지 않습니다. 내가 뭘 잘못 했니?
[[myAppManager sharedManager] storeData];
이것은 또한 호출하지 않습니다.
귀하의 코드는 나를 위해 작동라는 데이터를 저장한다. 정리가 잘되어있어서'MyAppManager'이어야하고 sharedManager가'id '가 아닌'instanceType'을 반환해야합니다 – Paulw11
myAppManager 클래스의 인스턴스를 명시 적으로 생성 해 보았고이를 사용하여 storeData 메소드를 호출 했습니까? – Arun
당신의 코드 형제를 시험해 보았습니다. 제게 잘 작동합니다. – user3182143