Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DeepLinkSDK/Categories/NSObject+DPLJSONObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- NSDictionary and NSArray will call `DPLJSONObject' on all of their items.
- Objects in an NSDictionary not keyed by an NSString will be removed.
- NSNumbers that are NaN or Inf will be represented by a string.
- NSDate objects will be represented as `timeIntervalSinceReferenceDate'.
- JSON incompatible objects will return their description.
- All NSNulls will be removed because who wants an NSNull.

Expand Down
9 changes: 9 additions & 0 deletions DeepLinkSDK/Categories/NSObject+DPLJSONObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ - (id)DPL_JSONObject {
@end


@implementation NSDate (DPLJSONObject)

- (id)DPL_JSONObject {
return @([self timeIntervalSinceReferenceDate]);
}

@end


@implementation NSArray (DPLJSONObject)

- (id)DPL_JSONObject {
Expand Down
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ DEPENDENCIES:

EXTERNAL SOURCES:
DeepLinkSDK:
:path: "."
:path: .

SPEC CHECKSUMS:
DeepLinkSDK: 82f36ed1bbf8fb549bb0dfb14b21852219c95384
Expand All @@ -25,4 +25,4 @@ SPEC CHECKSUMS:
OCMock: a10ea9f0a6e921651f96f78b6faee95ebc813b92
Specta: e5ad38f1b2227a23bc63d0b5a3b41c5e628f2851

COCOAPODS: 0.36.4
COCOAPODS: 0.37.0
6 changes: 6 additions & 0 deletions Tests/Categories/NSObject_DPLJSONObjectSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
expect(obj).to.equal(@{ @"inf": @"inf", @"nan": @"nan" });
});

it(@"converts date objects to timeIntervalSinceReferenceDate", ^{
NSDate *someDate = [NSDate date];
id obj = [someDate DPL_JSONObject];
expect([obj doubleValue]).to.equal([someDate timeIntervalSinceReferenceDate]);
});

it(@"removes non-string keys from dictionaries", ^{
NSDictionary *dict = @{ testURL: @"foo", @"bar": @"baz" };
id obj = [dict DPL_JSONObject];
Expand Down