Skip to content

Commit 6cd1fc5

Browse files
author
Alexis Oyama
committed
fix(VarCache): Fix crash when LPInboxMessage.data() was called and the data field is empty.
This only happens in swift. It was due to returning NSNull to id method.
1 parent 7aad38a commit 6cd1fc5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Leanplum-SDK/Classes/LPVarCache.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,26 +128,30 @@ + (NSArray *)getNameComponents:(NSString *)name
128128

129129
+ (id)traverse:(id)collection withKey:(id)key autoInsert:(BOOL)autoInsert
130130
{
131+
id result = nil;
131132
if ([collection respondsToSelector:@selector(objectForKey:)]) {
132-
id result = [collection objectForKey:key];
133+
result = [collection objectForKey:key];
133134
if (autoInsert && !result && [key isKindOfClass:NSString.class]) {
134135
result = [NSMutableDictionary dictionary];
135136
[collection setObject:result forKey:key];
136137
}
137-
return result;
138138
} else if ([collection isKindOfClass:[NSArray class]]) {
139139
int index = [key intValue];
140140
NSArray *arrayCollection = collection;
141141
if (arrayCollection.count > index) {
142-
id result = arrayCollection[index];
142+
result = arrayCollection[index];
143143
if (autoInsert && !result && [key isKindOfClass:NSString.class]) {
144144
result = [NSMutableArray array];
145145
[collection setObject:result atIndex:index];
146146
}
147-
return result;
148147
}
149148
}
150-
return nil;
149+
150+
if ([result isKindOfClass:[NSNull class]]) {
151+
return nil;
152+
}
153+
154+
return result;
151155
}
152156

153157
+ (void)registerFile:(NSString *)stringValue withDefaultValue:(NSString *)defaultValue

0 commit comments

Comments
 (0)