diff --git a/Code/CDAEntry.m b/Code/CDAEntry.m index a1ecad3..47051e0 100644 --- a/Code/CDAEntry.m +++ b/Code/CDAEntry.m @@ -130,9 +130,11 @@ -(NSString *)locale { } -(NSDictionary *)localizedDictionaryFromDictionary:(NSDictionary *)dictionary - forLocale:(NSString *)locale { + forLocale:(NSString *)locale + default:(BOOL)isDefault { NSDictionary* localizedDictionary = [super localizedDictionaryFromDictionary:dictionary - forLocale:locale]; + forLocale:locale + default:isDefault]; return [self parseDictionary:localizedDictionary]; } diff --git a/Code/CDAResource+Private.h b/Code/CDAResource+Private.h index 49f829f..d7f655c 100644 --- a/Code/CDAResource+Private.h +++ b/Code/CDAResource+Private.h @@ -26,7 +26,9 @@ client:(CDAClient*)client localizationAvailable:(BOOL)localizationAvailable; -(NSDictionary*)localizeFieldsFromDictionary:(NSDictionary*)fields; --(NSDictionary*)localizedDictionaryFromDictionary:(NSDictionary*)dictionary forLocale:(NSString*)locale; +-(NSDictionary*)localizedDictionaryFromDictionary:(NSDictionary*)dictionary + forLocale:(NSString*)locale + default:(BOOL)isDefault; -(NSDictionary*)parseDictionary:(NSDictionary*)dictionary; -(void)resolveLinksWithIncludedAssets:(NSDictionary*)assets entries:(NSDictionary*)entries; -(BOOL)updatedAfterDate:(NSDate*)date; diff --git a/Code/CDAResource.m b/Code/CDAResource.m index 9e4a0a8..b69f6c9 100644 --- a/Code/CDAResource.m +++ b/Code/CDAResource.m @@ -228,7 +228,7 @@ -(NSDictionary*)localizeFieldsFromDictionary:(NSDictionary*)fields { NSMutableDictionary* localizedFields = [@{} mutableCopy]; if (self.localizationAvailable) { - NSDictionary* defaultDictionary = [self localizedDictionaryFromDictionary:fields forLocale:self.defaultLocaleOfSpace]; + NSDictionary* defaultDictionary = [self localizedDictionaryFromDictionary:fields forLocale:self.defaultLocaleOfSpace default:YES]; localizedFields[self.defaultLocaleOfSpace] = defaultDictionary; for (NSString* locale in self.client.space.localeCodes) { @@ -237,7 +237,8 @@ -(NSDictionary*)localizeFieldsFromDictionary:(NSDictionary*)fields { } NSDictionary* localizedDictionary = [self localizedDictionaryFromDictionary:fields - forLocale:locale]; + forLocale:locale + default:NO]; localizedFields[locale] = [[CDAFallbackDictionary alloc] initWithDictionary:localizedDictionary fallbackDictionary:defaultDictionary]; } @@ -248,7 +249,9 @@ -(NSDictionary*)localizeFieldsFromDictionary:(NSDictionary*)fields { return [localizedFields copy]; } --(NSDictionary*)localizedDictionaryFromDictionary:(NSDictionary*)dictionary forLocale:(NSString*)locale { +-(NSDictionary*)localizedDictionaryFromDictionary:(NSDictionary*)dictionary + forLocale:(NSString*)locale + default:(BOOL)isDefault { NSParameterAssert(dictionary); NSParameterAssert(locale); @@ -257,11 +260,11 @@ -(NSDictionary*)localizedDictionaryFromDictionary:(NSDictionary*)dictionary forL [dictionary enumerateKeysAndObjectsUsingBlock:^(NSString* key, NSDictionary* value, BOOL *stop) { id localizedValue = value[locale]; - if (!localizedValue) { + if (!localizedValue && !isDefault) { return; } - result[key] = localizedValue; + result[key] = localizedValue ?: [NSNull null]; }]; return [result copy]; diff --git a/Tests/PersistenceBaseTest+Basic.m b/Tests/PersistenceBaseTest+Basic.m index eaa2b2c..758bc24 100644 --- a/Tests/PersistenceBaseTest+Basic.m +++ b/Tests/PersistenceBaseTest+Basic.m @@ -359,6 +359,7 @@ -(void)basic_syncEmptyField { NSArray* entries = [self.persistenceManager fetchEntriesFromDataStore]; XCTAssertEqual(1U, entries.count, @""); id updatedEntry = [entries firstObject]; + XCTAssertNotNil(updatedEntry); XCTAssertNil([updatedEntry valueForKey:@"name"]); EndBlock(); diff --git a/Tests/SyncTests.m b/Tests/SyncTests.m index 3afd61d..f74d535 100644 --- a/Tests/SyncTests.m +++ b/Tests/SyncTests.m @@ -610,7 +610,7 @@ -(void)testSyncEmptyField { [space performSynchronizationWithSuccess:^{ XCTAssertEqual(1U, space.entries.count, @""); CDAEntry* updatedEntry = space.entries[0]; - XCTAssertNil(updatedEntry.fields[@"test"]); + XCTAssertEqualObjects(updatedEntry.fields[@"test"], @""); EndBlock(); } failure:^(CDAResponse *response, NSError *error) {