Joined June 2017
·

MariaAngelova

Hi. I'm using this technique but i have a problem with the instance being deallocated when using Objective-C Automatic Reference Counting.
+ (iCloudKeyValueProxy *)instance {
static iCloudKeyValueProxy *sharedInstance = nil;
static dispatchoncet onceToken; // onceToken = 0
dispatch_once(&onceToken, ^{
sharedInstance = [[iCloudKeyValueProxy alloc] init];
});

return sharedInstance;

}

void iCloudKeyValueProxy_Fetch() {
iCloudKeyValueProxy* proxy = [iCloudKeyValueProxy instance];
[proxy fetch];
}

int iCloudKeyValueProxy_GetInt(NSString* key) {
iCloudKeyValueProxy* proxy = [iCloudKeyValueProxy instance];
NSNumber* nsValue = [proxy.storeLocal objectForKey:key];
return nsValue.intValue;
}

Then when calling Fetch and GetInt I get an error excbadaccess code=1 on the first line of iCloudKeyValueProxy_GetInt.
Any ideas how to make the instance leave on during the entire execution of the app?

Achievements
1 Karma
0 Total ProTip Views