diff --git a/Classes/Public/APSmartStorage.m b/Classes/Public/APSmartStorage.m index 71e9a29..3b36da0 100644 --- a/Classes/Public/APSmartStorage.m +++ b/Classes/Public/APSmartStorage.m @@ -188,7 +188,10 @@ - (void)objectFromFileWithURL:(NSURL *)url callback:(void (^)(id object, NSError if (data) { id result = weakSelf.parsingBlock ? weakSelf.parsingBlock(data, url) : data; - [weakSelf.memoryStorage setObject:result forURL:url]; + if (result) + { + [weakSelf.memoryStorage setObject:result forURL:url]; + } callback(result, nil); } else diff --git a/Spec/APSmartStorageSpec/APSmartStorageBaseSpec.mm b/Spec/APSmartStorageSpec/APSmartStorageBaseSpec.mm index 1894c2c..32528f2 100644 --- a/Spec/APSmartStorageSpec/APSmartStorageBaseSpec.mm +++ b/Spec/APSmartStorageSpec/APSmartStorageBaseSpec.mm @@ -126,6 +126,22 @@ - (void)objectFromMemoryWithURL:(NSURL *)objectURL callback:(void (^)(id object) in_time(checkObject) should_not be_nil; in_time(checkObject) should equal(@"APSmartStorage string"); }); + + it(@"should not throw exception if block returns nil", ^ + { + // parsing block + storage.parsingBlock = ^(NSData *data, NSURL *url) + { + return data ? nil : data; + }; + // loading object + __block BOOL isCallbackCalled = NO; + [storage loadObjectWithURL:objectURL callback:^(id object, NSError *error) + { + isCallbackCalled = YES; + }]; + in_time(isCallbackCalled) should equal(YES); + }); }); SPEC_END \ No newline at end of file