iOS에서 인스턴스 생성시 CSV 파일을 구문 분석 한 다음 결과를 보유하는 싱글 톤 개체가 있습니다. 이 객체를 보편적으로 액세스 가능하게 만들고 싶습니다. 앱을 종료 할 때까지 메모리에서 해제하지 않기를 바랍니다. 수동 유지를 수행 할 수 없도록 ARC를 실행 중입니다.앱이 종료 될 때까지 변수를 메모리에 유지하는 방법
내가 ARC와 함께 작동하도록 할 수있는 방법이 있습니까?
헤더 파일 :
@interface Foo : NSObject
+ (Foo *)sharedInstance;
@end
과하는 .m에 : 간단한 싱글은 .H에 ... 뭔가 같은 것
#import "ParserStore.h"
#import "RCParserObject.h"
#import "RCDetailItem.h"
static ParserStore *defaultStore;
@implementation ParserStore
@synthesize item, data, parsedData, fields, open;
# pragma mark -
# pragma mark Singleton Methods
+ (ParserStore *) defaultStore
{
if (!defaultStore)
{
defaultStore = [[super allocWithZone:NULL] init];
}
return defaultStore;
}
+ (id) allocWithZone:(NSZone *)zone
{
return [self defaultStore];
}
- (id) init
{
NSLog(@"Running init on parser store");
if (defaultStore)
{
NSLog(@"Self data count is %d, right before return", self.parsedData.count);
return defaultStore;
}
// NSLog(@"This better only happen once");
self = [super init];
[self setParsedData:[[NSMutableArray alloc] init]];
[self parseCSVFile:@"ContentNoPathFileExt2ASCII"];
[self categorizeData];
// NSLog(@"Self data count is %d when first created", self.parsedData.count);
return self;
}
@property (atomic, retain) RCParserObject *item;
@property (atomic, retain) NSMutableArray *data;
@property (atomic, retain) NSMutableArray *parsedData;
@property (atomic) int fields;
@property (atomic) bool open;
+ (ParserStore *) defaultStore;
- (void) parseCSVFile:(NSString*)file;
- (void) categorizeData;
@end
그것에 대한 참조. 싱글 톤 .m에서 정적 변수에 저장된 싱글 톤의 인스턴스입니까? –
나는 그것을하지 않았다, 당신은 저에게 구문을 말할 수 있는가? –
오, 신경 쓰지 마라. 나는 그것을했다. 그러나 나는 그것을 무가치하게 만들었다. 그렇지 않습니까? –