Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added test that fails if NSNull value is passed into attribution * added NSDictionary extension to filter out NSNull values * fixed a bug in the test * fix regression * removed unnecessary usage of removingNSNullValues, added tests to ensure that the right value is cached for postAttributionData
- Loading branch information
Showing
9 changed files
with
180 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
Purchases/FoundationExtensions/NSDictionary+RCExtensions.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// NSDictionary+RCExtensions.h | ||
// Purchases | ||
// | ||
// Created by Andrés Boedo on 9/29/20. | ||
// Copyright © 2020 Purchases. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
|
||
@interface NSDictionary (RCExtensions) | ||
|
||
- (NSDictionary *)removingNSNullValues; | ||
|
||
@end | ||
|
||
|
||
NS_ASSUME_NONNULL_END |
34 changes: 34 additions & 0 deletions
34
Purchases/FoundationExtensions/NSDictionary+RCExtensions.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// NSDictionary+RCExtensions.m | ||
// Purchases | ||
// | ||
// Created by Andrés Boedo on 9/29/20. | ||
// Copyright © 2020 Purchases. All rights reserved. | ||
// | ||
|
||
#import "NSDictionary+RCExtensions.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@implementation NSDictionary (RCExtensions) | ||
|
||
- (NSDictionary *)removingNSNullValues { | ||
NSMutableDictionary *result = [[NSMutableDictionary alloc] init]; | ||
|
||
NSEnumerator *enumerator = [self keyEnumerator]; | ||
id key; | ||
|
||
while ((key = enumerator.nextObject)) { | ||
id value = self[key]; | ||
if (![value isKindOfClass:NSNull.class]) { | ||
result[key] = value; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
NS_ASSUME_NONNULL_END | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// NSDictionaryExtensionsTests.swift | ||
// PurchasesCoreSwiftTests | ||
// | ||
// Created by Andrés Boedo on 9/28/20. | ||
// Copyright © 2020 Purchases. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
import Nimble | ||
|
||
@testable import Purchases | ||
|
||
class NSDictionaryExtensionsTests: XCTestCase { | ||
func testRemovingNSNullValuesFiltersCorrectly() { | ||
let testValues: NSDictionary = [ | ||
"instrument": "guitar", | ||
"type": 1, | ||
"volume": NSNull() | ||
] | ||
let expectedValues: NSDictionary = [ | ||
"instrument": "guitar", | ||
"type": 1 | ||
] | ||
|
||
expect(testValues.removingNSNullValues() as NSDictionary) == expectedValues | ||
} | ||
|
||
func testRemovingNSNullValuesReturnsEmptyIfOriginalIsEmpty() { | ||
let testValues = NSDictionary() | ||
|
||
expect(testValues.removingNSNullValues() as NSDictionary) == testValues | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters