Skip to content

Commit 690525f

Browse files
author
Josh Holtz
committed
Fix for mapKeysToProperties not working for linked objects with links
1 parent bab3c72 commit 690525f

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

Classes/JSONAPIResource.m

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,6 @@ - (id)initWithDictionary:(NSDictionary*)dict withLinked:(NSDictionary*)linked {
6464
[self setWithDictionary:dict];
6565
[self linkLinks:linked];
6666

67-
68-
for (NSString *key in [self mapKeysToProperties]) {
69-
if ([key hasPrefix:@"links."] == YES) {
70-
71-
NSString *propertyName = [[self mapKeysToProperties] objectForKey:key];
72-
NSString *linkedResource = [key stringByReplacingOccurrencesOfString:@"links." withString:@""];
73-
74-
id resource = [self linkedResourceForKey:linkedResource];
75-
if (resource != nil) {
76-
@try {
77-
[self setValue:resource forKey:propertyName];
78-
}
79-
@catch (NSException *exception) {
80-
NSLog(@"JSONAPIResource Warning - %@", [exception description]);
81-
}
82-
}
83-
84-
}
85-
}
86-
8767
}
8868
return self;
8969
}
@@ -174,6 +154,26 @@ - (void)linkLinks:(NSDictionary*)linked {
174154

175155
}
176156
}
157+
158+
// Link links for mapped key to properties
159+
for (NSString *key in [self mapKeysToProperties]) {
160+
if ([key hasPrefix:@"links."] == YES) {
161+
162+
NSString *propertyName = [[self mapKeysToProperties] objectForKey:key];
163+
NSString *linkedResource = [key stringByReplacingOccurrencesOfString:@"links." withString:@""];
164+
165+
id resource = [self linkedResourceForKey:linkedResource];
166+
if (resource != nil) {
167+
@try {
168+
[self setValue:resource forKey:propertyName];
169+
}
170+
@catch (NSException *exception) {
171+
NSLog(@"JSONAPIResource Warning - %@", [exception description]);
172+
}
173+
}
174+
175+
}
176+
}
177177
}
178178

179179
@end

0 commit comments

Comments
 (0)