- Fix AccessToken Save, SharedInstance

- Fix crash in removeObserver PNObject
This commit is contained in:
giuseppenuc committed 2016-02-03 02:21:44 +01:00
1 parent 41c856b3c9
commit c23b1e0e38
8 files changed
+187 -107

No files matched your search

+22 -14
View File
@@ -75,9 +75,9 @@
NSMutableDictionary * objectDict = [[NSMutableDictionary alloc] initWithDictionary:[[self class] objcetMapping]];
[objectDict addEntriesFromDictionary:[PNObject objcetMapping]];
_objectMapping = objectDict;
_JSONObject = objectDict;
NSAssert(_objectMapping, @"You must create objectMapping");
NSAssert(_JSONObject, @"You must create objectMapping");
_singleInstance = [[self class] singleInstance];
@@ -102,9 +102,9 @@
NSMutableDictionary * objectDict = [[NSMutableDictionary alloc] initWithDictionary:[[self class] objcetMapping]];
[objectDict addEntriesFromDictionary:[PNObject objcetMapping]];
_objectMapping = objectDict;
_JSONObject = objectDict;
NSAssert(_objectMapping, @"You must create objectMapping");
NSAssert(_JSONObject, @"You must create objectMapping");
_singleInstance = [[self class] singleInstance];
@@ -112,7 +112,7 @@
}
NSAssert(_objectMapping, @"You must create objectMapping");
NSAssert(_JSONObject, @"You must create objectMapping");
_JSON = [[NSMutableDictionary alloc] initWithDictionary:JSON];
[self populateObjectFromJSON:_JSON];
@@ -129,8 +129,8 @@
NSDictionary *properties = [PNObject propertiesForClass:self.class];
for (NSString* propertyName in _objectMapping) {
id mappingValue = [_objectMapping objectForKey:propertyName];
for (NSString* propertyName in _JSONObject) {
id mappingValue = [_JSONObject objectForKey:propertyName];
if([mappingValue isKindOfClass:NSDictionary.class]) {
mappedJSONKey = [mappingValue valueForKey:@"key"];
@@ -205,7 +205,7 @@
@"NSArray" : ^{
NSMutableArray *arr = [NSMutableArray array];
for(id PNObject in value) {
SEL selector = NSSelectorFromString(@"getJSONObject");
SEL selector = NSSelectorFromString(@"JSONObject");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: [[PNObject class] instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:PNObject];
@@ -224,7 +224,7 @@
PNObject *val = [[NSClassFromString(mappedJSONType) alloc] initWithJSON:JSONObject];
[arr addObject:val];
SEL selector = NSSelectorFromString(@"getJSONObject");
SEL selector = NSSelectorFromString(@"JSONObject");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:value];
@@ -238,7 +238,7 @@
}[propertyType] ?: ^{
BOOL isPNObjectSubclass = [NSClassFromString(propertyType) isSubclassOfClass:[PNObject class]];
if(isPNObjectSubclass) {
SEL selector = NSSelectorFromString(@"getJSONObject");
SEL selector = NSSelectorFromString(@"JSONObject");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:value];
@@ -260,7 +260,7 @@
}
- (NSDictionary* _Nonnull) getJSONObject {
- (NSDictionary* _Nonnull) JSONObject {
if (!_JSON) {
return [self reverseMapping];
}
@@ -321,7 +321,6 @@
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
NSLogDebug(@"%@",[[[self class] objcetMapping] objectForKey:keyPath]);
[_JSON setObject:[change objectForKey:@"new"] forKey:[[[self class] objcetMapping] objectForKey:keyPath]];
}
@@ -333,10 +332,19 @@
if ([propertyName isEqualToString:@"description"] || [propertyName isEqualToString:@"debugDescription"]) {
continue;
}
[self removeObserver:self forKeyPath:propertyName];
@try {
[self removeObserver:self forKeyPath:propertyName];
}
@catch (NSException *exception) {
}
@finally {
}
}
_JSON = nil;
_objectMapping = nil;
_JSONObject = nil;
_objID = nil;
_createdAt = nil;