Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios] Fix analyzer fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Rex committed Apr 17, 2019
1 parent 7e1ca02 commit d82b0b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion platform/darwin/src/NSExpression+MGLAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ FOUNDATION_EXTERN MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionI
@return An initialized expression equivalent to `object`, suitable for use as
the value of a style layer attribute.
*/
+ (instancetype)expressionWithMGLJSONObject:(id)object NS_SWIFT_NAME(init(mglJSONObject:));
+ (instancetype)expressionWithMGLJSONObject:(nullable id)object NS_SWIFT_NAME(init(mglJSONObject:));

/**
An equivalent Foundation object that can be serialized as JSON.
Expand Down
35 changes: 16 additions & 19 deletions platform/darwin/src/NSExpression+MGLAdditions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -792,24 +792,19 @@ + (instancetype)expressionWithMGLJSONObject:(id)object {
} else if ([curveType isEqualToString:@"cubic-bezier"]) {
curveParameters = @[@"literal", [interpolationOptions subarrayWithRange:NSMakeRange(1, 4)]];
}

NSAssert(curveParameters, @"curveParameters should be non-nil");
if (curveParameters) {
NSExpression *curveParameterExpression = [NSExpression expressionWithMGLJSONObject:curveParameters];
argumentObjects = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)];
NSExpression *inputExpression = [NSExpression expressionWithMGLJSONObject:argumentObjects.firstObject];
NSArray *stopExpressions = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)];
NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:stopExpressions.count / 2];
NSEnumerator *stopEnumerator = stopExpressions.objectEnumerator;
while (NSNumber *key = stopEnumerator.nextObject) {
NSExpression *valueExpression = stopEnumerator.nextObject;
stops[key] = [NSExpression expressionWithMGLJSONObject:valueExpression];
}
NSExpression *stopExpression = [NSExpression expressionForConstantValue:stops];
return [NSExpression expressionForFunction:@"mgl_interpolate:withCurveType:parameters:stops:"
arguments:@[inputExpression, curveTypeExpression, curveParameterExpression, stopExpression]];
NSExpression *curveParameterExpression = [NSExpression expressionWithMGLJSONObject:curveParameters];
argumentObjects = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)];
NSExpression *inputExpression = [NSExpression expressionWithMGLJSONObject:argumentObjects.firstObject];
NSArray *stopExpressions = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)];
NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:stopExpressions.count / 2];
NSEnumerator *stopEnumerator = stopExpressions.objectEnumerator;
while (NSNumber *key = stopEnumerator.nextObject) {
NSExpression *valueExpression = stopEnumerator.nextObject;
stops[key] = [NSExpression expressionWithMGLJSONObject:valueExpression];
}

NSExpression *stopExpression = [NSExpression expressionForConstantValue:stops];
return [NSExpression expressionForFunction:@"mgl_interpolate:withCurveType:parameters:stops:"
arguments:@[inputExpression, curveTypeExpression, curveParameterExpression, stopExpression]];
} else if ([op isEqualToString:@"step"]) {
NSExpression *inputExpression = [NSExpression expressionWithMGLJSONObject:argumentObjects[0]];
NSArray *stopExpressions = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)];
Expand Down Expand Up @@ -1031,7 +1026,7 @@ - (id)mgl_jsonExpressionObject {
}

case NSKeyPathExpressionType: {
NSArray *expressionObject = @[];
NSArray *expressionObject;
NSArray *keyPath = [self.keyPath componentsSeparatedByString:@"."];
for (NSString *pathComponent in keyPath) {
if (expressionObject) {
Expand All @@ -1042,7 +1037,9 @@ - (id)mgl_jsonExpressionObject {
}

NSAssert(expressionObject.count > 0, @"expressionObject should be non-empty");
return expressionObject;

// Return a non-null value to quieten static analysis
return expressionObject ?: @[];
}

case NSFunctionExpressionType: {
Expand Down

0 comments on commit d82b0b7

Please sign in to comment.