Skip to content

Commit f53c0ae

Browse files
committed
Refactor asset retrieval logic in Entry.m for improved readability and efficiency. Update project scheme version and enable code coverage settings. Enhance JSON handling in NSObject+Extensions.m with nil checks and type validation. Add multiple test files to project configuration.
1 parent 1aabf13 commit f53c0ae

17 files changed

+4443
-16
lines changed

Contentstack.xcodeproj/project.pbxproj

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,22 @@
107107
64B3EA282BF7C4AF009E0F38 /* libThirdPartyExtension.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 238E841B1B4FE29A00BFDB32 /* libThirdPartyExtension.a */; };
108108
64F5220E2BF5C76E00AE6E0F /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 64F5220D2BF5C76E00AE6E0F /* PrivacyInfo.xcprivacy */; };
109109
64F5220F2BF5C76E00AE6E0F /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 64F5220D2BF5C76E00AE6E0F /* PrivacyInfo.xcprivacy */; };
110+
6787D39B2EBC671F00A2F637 /* NSObjectExtensionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 6787D39A2EBC671F00A2F637 /* NSObjectExtensionsTest.m */; };
111+
6787D39D2EBC673500A2F637 /* EntryAdvancedTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 6787D39C2EBC673500A2F637 /* EntryAdvancedTest.m */; };
112+
6787D39F2EBC673600A2F637 /* QueryAdvancedTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 6787D39E2EBC673600A2F637 /* QueryAdvancedTest.m */; };
110113
678803D22DED82A100E4AA75 /* GlobalField.h in Headers */ = {isa = PBXBuildFile; fileRef = 678803D12DED829800E4AA75 /* GlobalField.h */; };
111114
678803D42DED82AF00E4AA75 /* GlobalField.m in Sources */ = {isa = PBXBuildFile; fileRef = 678803D32DED82AC00E4AA75 /* GlobalField.m */; };
112115
678803D62DEDB24800E4AA75 /* GlobalFieldTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 678803D52DEDB23800E4AA75 /* GlobalFieldTest.m */; };
116+
67AA391A2EBB354F00C0E2C0 /* TaxonomyTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 67AA39192EBB354F00C0E2C0 /* TaxonomyTest.m */; };
117+
67AA391C2EBB355600C0E2C0 /* QueryResultTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 67AA391B2EBB355600C0E2C0 /* QueryResultTest.m */; };
118+
67AA391E2EBB355A00C0E2C0 /* QueryEdgeCaseTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 67AA391D2EBB355A00C0E2C0 /* QueryEdgeCaseTest.m */; };
119+
67AA39202EBB355F00C0E2C0 /* GroupTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 67AA391F2EBB355F00C0E2C0 /* GroupTest.m */; };
120+
67AA39222EBB356400C0E2C0 /* EntryEdgeCaseTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 67AA39212EBB356400C0E2C0 /* EntryEdgeCaseTest.m */; };
121+
67AA39242EBB356800C0E2C0 /* ContentTypeEdgeCaseTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 67AA39232EBB356800C0E2C0 /* ContentTypeEdgeCaseTest.m */; };
122+
67AA39262EBB356D00C0E2C0 /* AssetLibraryTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 67AA39252EBB356D00C0E2C0 /* AssetLibraryTest.m */; };
123+
67AA39282EBB357400C0E2C0 /* AssetEdgeCaseTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 67AA39272EBB357400C0E2C0 /* AssetEdgeCaseTest.m */; };
124+
BFDECB7ADED46A51700FE398 /* ContentstackMainTest.m in Sources */ = {isa = PBXBuildFile; fileRef = DD745A781E5B6171D9E68BB8 /* ContentstackMainTest.m */; };
125+
DA052EBF01230642692DA859 /* QueryResultAdvancedTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 55FB34FC5E57D6E11D51A686 /* QueryResultAdvancedTest.m */; };
113126
E653FF942F28495541E9B22B /* libPods-Contentstack.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4514C6AB47DF26BA926C681A /* libPods-Contentstack.a */; };
114127
/* End PBXBuildFile section */
115128

@@ -226,6 +239,7 @@
226239
4714B7D32C5EAFCC004E941E /* Taxonomy.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Taxonomy.m; sourceTree = "<group>"; };
227240
4714B7D52C5EAFF5004E941E /* Taxonomy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Taxonomy.h; sourceTree = "<group>"; };
228241
473AFDAF2CA22233002D331D /* config.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = config.json; sourceTree = "<group>"; };
242+
55FB34FC5E57D6E11D51A686 /* QueryResultAdvancedTest.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = QueryResultAdvancedTest.m; sourceTree = "<group>"; };
229243
565E11A91BD76654005AD47F /* MMDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MMDocument.h; sourceTree = "<group>"; };
230244
565E11AA1BD76654005AD47F /* MMDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MMDocument.m; sourceTree = "<group>"; };
231245
565E11AB1BD76654005AD47F /* MMDocument_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MMDocument_Private.h; sourceTree = "<group>"; };
@@ -247,13 +261,25 @@
247261
606DDA20A6F0593F40494FED /* Pods-ContentstackTest.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ContentstackTest.release.xcconfig"; path = "Target Support Files/Pods-ContentstackTest/Pods-ContentstackTest.release.xcconfig"; sourceTree = "<group>"; };
248262
609D1D72B25D2FBE4E26FA70 /* Pods-ContentstackTest.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ContentstackTest.debug.xcconfig"; path = "Target Support Files/Pods-ContentstackTest/Pods-ContentstackTest.debug.xcconfig"; sourceTree = "<group>"; };
249263
64F5220D2BF5C76E00AE6E0F /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
264+
6787D39A2EBC671F00A2F637 /* NSObjectExtensionsTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NSObjectExtensionsTest.m; sourceTree = "<group>"; };
265+
6787D39C2EBC673500A2F637 /* EntryAdvancedTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EntryAdvancedTest.m; sourceTree = "<group>"; };
266+
6787D39E2EBC673600A2F637 /* QueryAdvancedTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QueryAdvancedTest.m; sourceTree = "<group>"; };
250267
678803D12DED829800E4AA75 /* GlobalField.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GlobalField.h; sourceTree = "<group>"; };
251268
678803D32DED82AC00E4AA75 /* GlobalField.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GlobalField.m; sourceTree = "<group>"; };
252269
678803D52DEDB23800E4AA75 /* GlobalFieldTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GlobalFieldTest.m; sourceTree = "<group>"; };
270+
67AA39192EBB354F00C0E2C0 /* TaxonomyTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TaxonomyTest.m; sourceTree = "<group>"; };
271+
67AA391B2EBB355600C0E2C0 /* QueryResultTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QueryResultTest.m; sourceTree = "<group>"; };
272+
67AA391D2EBB355A00C0E2C0 /* QueryEdgeCaseTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QueryEdgeCaseTest.m; sourceTree = "<group>"; };
273+
67AA391F2EBB355F00C0E2C0 /* GroupTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GroupTest.m; sourceTree = "<group>"; };
274+
67AA39212EBB356400C0E2C0 /* EntryEdgeCaseTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EntryEdgeCaseTest.m; sourceTree = "<group>"; };
275+
67AA39232EBB356800C0E2C0 /* ContentTypeEdgeCaseTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ContentTypeEdgeCaseTest.m; sourceTree = "<group>"; };
276+
67AA39252EBB356D00C0E2C0 /* AssetLibraryTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AssetLibraryTest.m; sourceTree = "<group>"; };
277+
67AA39272EBB357400C0E2C0 /* AssetEdgeCaseTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AssetEdgeCaseTest.m; sourceTree = "<group>"; };
253278
7EB1C6B5FF6A451CEB50B3A4 /* libPods-ContentstackTest.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ContentstackTest.a"; sourceTree = BUILT_PRODUCTS_DIR; };
254279
8B7BE798B2EEFA3CC2763E3F /* Pods-Contentstack.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Contentstack.release.xcconfig"; path = "Target Support Files/Pods-Contentstack/Pods-Contentstack.release.xcconfig"; sourceTree = "<group>"; };
255280
9980728A1E1BDC5000524FD3 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
256281
ADFEA7B22B9D9042C8508BEC /* Pods-Contentstack.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Contentstack.debug.xcconfig"; path = "Target Support Files/Pods-Contentstack/Pods-Contentstack.debug.xcconfig"; sourceTree = "<group>"; };
282+
DD745A781E5B6171D9E68BB8 /* ContentstackMainTest.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = ContentstackMainTest.m; sourceTree = "<group>"; };
257283
/* End PBXFileReference section */
258284

259285
/* Begin PBXFrameworksBuildPhase section */
@@ -439,10 +465,23 @@
439465
isa = PBXGroup;
440466
children = (
441467
0F41A91025C7CC9C007EF2DA /* ContentstackTest.m */,
468+
67AA39192EBB354F00C0E2C0 /* TaxonomyTest.m */,
469+
67AA391B2EBB355600C0E2C0 /* QueryResultTest.m */,
470+
6787D39A2EBC671F00A2F637 /* NSObjectExtensionsTest.m */,
471+
67AA391D2EBB355A00C0E2C0 /* QueryEdgeCaseTest.m */,
472+
6787D39C2EBC673500A2F637 /* EntryAdvancedTest.m */,
473+
67AA39252EBB356D00C0E2C0 /* AssetLibraryTest.m */,
474+
67AA39272EBB357400C0E2C0 /* AssetEdgeCaseTest.m */,
475+
6787D39E2EBC673600A2F637 /* QueryAdvancedTest.m */,
476+
67AA39232EBB356800C0E2C0 /* ContentTypeEdgeCaseTest.m */,
477+
67AA39212EBB356400C0E2C0 /* EntryEdgeCaseTest.m */,
478+
67AA391F2EBB355F00C0E2C0 /* GroupTest.m */,
442479
0F41A91125C7CC9C007EF2DA /* SyncTest.m */,
443480
678803D52DEDB23800E4AA75 /* GlobalFieldTest.m */,
444481
23A53F591E277CD3001DBE35 /* Info.plist */,
445482
473AFDAF2CA22233002D331D /* config.json */,
483+
DD745A781E5B6171D9E68BB8 /* ContentstackMainTest.m */,
484+
55FB34FC5E57D6E11D51A686 /* QueryResultAdvancedTest.m */,
446485
);
447486
path = ContentstackTest;
448487
sourceTree = "<group>";
@@ -834,9 +873,22 @@
834873
isa = PBXSourcesBuildPhase;
835874
buildActionMask = 2147483647;
836875
files = (
876+
67AA391A2EBB354F00C0E2C0 /* TaxonomyTest.m in Sources */,
877+
67AA39222EBB356400C0E2C0 /* EntryEdgeCaseTest.m in Sources */,
878+
67AA39262EBB356D00C0E2C0 /* AssetLibraryTest.m in Sources */,
879+
6787D39B2EBC671F00A2F637 /* NSObjectExtensionsTest.m in Sources */,
880+
67AA391E2EBB355A00C0E2C0 /* QueryEdgeCaseTest.m in Sources */,
837881
0F41A91425C7CC9C007EF2DA /* ContentstackTest.m in Sources */,
882+
6787D39F2EBC673600A2F637 /* QueryAdvancedTest.m in Sources */,
883+
67AA391C2EBB355600C0E2C0 /* QueryResultTest.m in Sources */,
838884
0F41A91525C7CC9C007EF2DA /* SyncTest.m in Sources */,
885+
6787D39D2EBC673500A2F637 /* EntryAdvancedTest.m in Sources */,
886+
67AA39242EBB356800C0E2C0 /* ContentTypeEdgeCaseTest.m in Sources */,
887+
67AA39282EBB357400C0E2C0 /* AssetEdgeCaseTest.m in Sources */,
888+
67AA39202EBB355F00C0E2C0 /* GroupTest.m in Sources */,
839889
678803D62DEDB24800E4AA75 /* GlobalFieldTest.m in Sources */,
890+
BFDECB7ADED46A51700FE398 /* ContentstackMainTest.m in Sources */,
891+
DA052EBF01230642692DA859 /* QueryResultAdvancedTest.m in Sources */,
840892
);
841893
runOnlyForDeploymentPostprocessing = 0;
842894
};

Contentstack.xcodeproj/xcshareddata/xcschemes/Contentstack.xcscheme

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
33
LastUpgradeVersion = "1540"
4-
version = "1.3">
4+
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"
77
buildImplicitDependencies = "YES">
@@ -26,7 +26,9 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
shouldUseLaunchSchemeArgsEnv = "YES">
29+
shouldUseLaunchSchemeArgsEnv = "YES"
30+
codeCoverageEnabled = "YES"
31+
onlyGenerateCoverageForSpecifiedTargets = "YES">
3032
<MacroExpansion>
3133
<BuildableReference
3234
BuildableIdentifier = "primary"
@@ -36,6 +38,15 @@
3638
ReferencedContainer = "container:Contentstack.xcodeproj">
3739
</BuildableReference>
3840
</MacroExpansion>
41+
<CodeCoverageTargets>
42+
<BuildableReference
43+
BuildableIdentifier = "primary"
44+
BlueprintIdentifier = "230B38BF1C16E98B00444A14"
45+
BuildableName = "Contentstack.framework"
46+
BlueprintName = "Contentstack"
47+
ReferencedContainer = "container:Contentstack.xcodeproj">
48+
</BuildableReference>
49+
</CodeCoverageTargets>
3950
<Testables>
4051
<TestableReference
4152
skipped = "NO">
@@ -46,6 +57,10 @@
4657
BlueprintName = "ContentstackTest"
4758
ReferencedContainer = "container:Contentstack.xcodeproj">
4859
</BuildableReference>
60+
<LocationScenarioReference
61+
identifier = "com.apple.dt.IDEFoundation.CurrentLocationScenarioIdentifier"
62+
referenceType = "1">
63+
</LocationScenarioReference>
4964
</TestableReference>
5065
</Testables>
5166
</TestAction>

Contentstack/Entry.m

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,14 @@ - (Asset *)assetForKey:(NSString *)key {
350350
- (NSArray *)assetsForKey:(NSString *)key {
351351
NSMutableArray *fileArray = [NSMutableArray array];
352352
id obj = [self.objectProperties objectForKey:key];
353-
if (obj && [obj isKindOfClass:[NSArray class]]) {
354-
NSArray *arr = (NSArray *)obj;
355-
for (NSDictionary *dict in arr) {
356-
Asset *file = [self assetFile:dict];
357-
if (file && ![file isKindOfClass:[NSNull class]]) {
358-
[fileArray addObject:file];
359-
}
353+
if (!(obj && [obj isKindOfClass:[NSArray class]])) {
354+
return fileArray;
355+
}
356+
NSArray *arr = (NSArray *)obj;
357+
for (NSDictionary *dict in arr) {
358+
Asset *file = [self assetFile:dict];
359+
if (file && ![file isKindOfClass:[NSNull class]]) {
360+
[fileArray addObject:file];
360361
}
361362
}
362363
return fileArray;

ContentstackInternal/NSObject+Extensions.m

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,26 +267,32 @@ - (void)assertPropertyTypes:(NSDictionary *)properties {
267267
}
268268

269269
- (NSDictionary *)dictionaryFromJSONData:(NSData *)data {
270-
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
271-
return dict;
270+
if (data == nil) { return nil; }
271+
if (data.length == 0) { return nil; }
272+
id obj = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
273+
return [obj isKindOfClass:[NSDictionary class]] ? obj : nil;
272274
}
273275

274276
- (NSData *)jsonDataFromDictonary:(NSDictionary *)dict {
275-
NSData *JSONData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:NULL];
276-
return JSONData;
277+
if (dict == nil) { return nil; }
278+
return [NSJSONSerialization dataWithJSONObject:dict options:0 error:NULL];
277279
}
278280

279281
- (NSString *)jsonStringFromDictonary:(NSDictionary *)dict {
280-
NSData *JSONData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:NULL];
282+
NSData *JSONData = [self jsonDataFromDictonary:dict];
283+
if (JSONData == nil) { return nil; }
281284
return [[NSString alloc] initWithData:JSONData encoding:NSUTF8StringEncoding];
282285
}
283286

284287
- (NSArray *)arrayFromJSONData:(NSData *)data {
285-
NSArray *array = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
286-
return array;
288+
if (data == nil) { return nil; }
289+
if (data.length == 0) { return nil; }
290+
id obj = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
291+
return [obj isKindOfClass:[NSArray class]] ? obj : nil;
287292
}
288293

289294
- (NSString *)jsonStringFromArray:(NSArray*)array {
295+
if (array == nil) { return nil; }
290296
NSData *JSONData = [NSJSONSerialization dataWithJSONObject:array options:0 error:NULL];
291297
return [[NSString alloc] initWithData:JSONData encoding:NSUTF8StringEncoding];
292298
}

0 commit comments

Comments
 (0)