Skip to content

Commit dce4c55

Browse files
Merge pull request #59 from contentstack/feat/DX-2981-Global-fields-impl
global fields implementation and testcases
2 parents d9c38c2 + 3cd8f1b commit dce4c55

File tree

14 files changed

+709
-10
lines changed

14 files changed

+709
-10
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
### Version: 3.14.1
2+
#### Date: Jun-16-2025
3+
4+
##### Enhancement:
5+
- Added support for Global Fields
6+
7+
### Version: 3.14.0
8+
#### Date: Oct-04-2024
9+
10+
##### Enhancement:
11+
- Early access header support
12+
- Fetch asset by query
13+
14+
### Version: 3.13.0
15+
#### Date: Aug-23-2024
16+
17+
##### Enhancement:
18+
- Added support for Taxonomy
19+
120
### Version: 3.12.3
221
#### Date: May-16-2023
322

Contentstack.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Contentstack'
3-
s.version = '3.14.0'
3+
s.version = '3.14.1'
44
s.summary = 'Contentstack is a headless CMS with an API-first approach that puts content at the centre.'
55

66
s.description = <<-DESC

Contentstack.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@
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+
678803D22DED82A100E4AA75 /* GlobalField.h in Headers */ = {isa = PBXBuildFile; fileRef = 678803D12DED829800E4AA75 /* GlobalField.h */; };
111+
678803D42DED82AF00E4AA75 /* GlobalField.m in Sources */ = {isa = PBXBuildFile; fileRef = 678803D32DED82AC00E4AA75 /* GlobalField.m */; };
112+
678803D62DEDB24800E4AA75 /* GlobalFieldTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 678803D52DEDB23800E4AA75 /* GlobalFieldTest.m */; };
110113
E653FF942F28495541E9B22B /* libPods-Contentstack.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4514C6AB47DF26BA926C681A /* libPods-Contentstack.a */; };
111114
/* End PBXBuildFile section */
112115

@@ -244,6 +247,9 @@
244247
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>"; };
245248
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>"; };
246249
64F5220D2BF5C76E00AE6E0F /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
250+
678803D12DED829800E4AA75 /* GlobalField.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GlobalField.h; sourceTree = "<group>"; };
251+
678803D32DED82AC00E4AA75 /* GlobalField.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GlobalField.m; sourceTree = "<group>"; };
252+
678803D52DEDB23800E4AA75 /* GlobalFieldTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GlobalFieldTest.m; sourceTree = "<group>"; };
247253
7EB1C6B5FF6A451CEB50B3A4 /* libPods-ContentstackTest.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ContentstackTest.a"; sourceTree = BUILT_PRODUCTS_DIR; };
248254
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>"; };
249255
9980728A1E1BDC5000524FD3 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
@@ -306,6 +312,8 @@
306312
230B38C11C16E98B00444A14 /* Contentstack */ = {
307313
isa = PBXGroup;
308314
children = (
315+
678803D12DED829800E4AA75 /* GlobalField.h */,
316+
678803D32DED82AC00E4AA75 /* GlobalField.m */,
309317
0F9C0FA4221ADAC80091205A /* Asset.h */,
310318
0F9C0FA3221ADAC80091205A /* Asset.m */,
311319
0F9C0F98221ADAC70091205A /* AssetLibrary.h */,
@@ -432,6 +440,7 @@
432440
children = (
433441
0F41A91025C7CC9C007EF2DA /* ContentstackTest.m */,
434442
0F41A91125C7CC9C007EF2DA /* SyncTest.m */,
443+
678803D52DEDB23800E4AA75 /* GlobalFieldTest.m */,
435444
23A53F591E277CD3001DBE35 /* Info.plist */,
436445
473AFDAF2CA22233002D331D /* config.json */,
437446
);
@@ -534,6 +543,7 @@
534543
230B39011C16EB8D00444A14 /* ISO8601DateFormatter.h in Headers */,
535544
23A53F401E276C83001DBE35 /* CSIOInternalHeaders.h in Headers */,
536545
0F9C0FB1221ADAC90091205A /* AssetLibrary.h in Headers */,
546+
678803D22DED82A100E4AA75 /* GlobalField.h in Headers */,
537547
0FD6BAEF29CD6E73001A0930 /* CSURLSessionDelegate.h in Headers */,
538548
0F9C0FB6221ADAC90091205A /* Config.h in Headers */,
539549
0F9C0FC2221ADAC90091205A /* Query.h in Headers */,
@@ -777,6 +787,7 @@
777787
230B38FA1C16EB8000444A14 /* MMGenerator.h in Sources */,
778788
0FEAEF2B2361A18600985FF9 /* CSURLSessionManager.m in Sources */,
779789
230B38FB1C16EB8000444A14 /* MMHTMLParser.h in Sources */,
790+
678803D42DED82AF00E4AA75 /* GlobalField.m in Sources */,
780791
230B38FC1C16EB8000444A14 /* MMMarkdown-Prefix.pch in Sources */,
781792
0F9C0FC4221ADAC90091205A /* Config.m in Sources */,
782793
230B38FD1C16EB8000444A14 /* MMMarkdown.h in Sources */,
@@ -825,6 +836,7 @@
825836
files = (
826837
0F41A91425C7CC9C007EF2DA /* ContentstackTest.m in Sources */,
827838
0F41A91525C7CC9C007EF2DA /* SyncTest.m in Sources */,
839+
678803D62DEDB24800E4AA75 /* GlobalFieldTest.m in Sources */,
828840
);
829841
runOnlyForDeploymentPostprocessing = 0;
830842
};

Contentstack/GlobalField.h

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
//
2+
// GlobalField.h
3+
// Contentstack
4+
//
5+
// Created by Reeshika Hosmani on 02/06/25.
6+
// Copyright © 2025 Contentstack. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import <Contentstack/ContentstackDefinitions.h>
11+
12+
13+
BUILT_ASSUME_NONNULL_BEGIN
14+
15+
@interface GlobalField : NSObject
16+
17+
- (instancetype)init UNAVAILABLE_ATTRIBUTE;
18+
//- (instancetype)initWithStack:(Stack*)stack;
19+
//- (instancetype)initWithStack:(Stack*)stack withName:(NSString*)globalFieldName;
20+
21+
/**----------------------------------------------------------------------------------------
22+
* @name Properties
23+
*-----------------------------------------------------------------------------------------
24+
*/
25+
26+
/**
27+
* Readonly property to check title of GlobalField
28+
*/
29+
@property (nonatomic, copy, readonly) NSString *title;
30+
31+
/**
32+
* Readonly property to check version
33+
*/
34+
@property (nonatomic, assign, readonly) unsigned int version;
35+
36+
/**
37+
* Readonly property to check description
38+
*/
39+
@property (nonatomic, copy, readonly) NSString *Description;
40+
41+
/**
42+
* Readonly property to check value of global field's uid
43+
*/
44+
@property (nonatomic, copy, readonly) NSString *uid;
45+
46+
/**
47+
* Readonly property to check createdAt of global field
48+
*/
49+
@property (nonatomic, copy, readonly) NSDate *createdAt;
50+
51+
/**
52+
* Readonly property to check updatedAt of global field
53+
*/
54+
@property (nonatomic, copy, readonly) NSDate *updatedAt;
55+
56+
/**
57+
* Readonly property to check the branch
58+
*/
59+
@property (nonatomic, copy, readonly) NSString *branch;
60+
61+
/**
62+
* Readonly property to get schema of global field
63+
*/
64+
@property (nonatomic, copy, readonly) NSArray<NSDictionary *> *schema;
65+
66+
/**
67+
* Readonly property to check if global field is inbuilt class
68+
*/
69+
@property (nonatomic, assign, readonly) BOOL inbuiltClass;
70+
71+
/**
72+
* Readonly property to check if global field maintains revisions
73+
*/
74+
@property (nonatomic, assign, readonly) BOOL maintainRevisions;
75+
76+
/**
77+
* Readonly property to get last activity of global field
78+
*/
79+
@property (nonatomic, copy, readonly) NSDictionary *lastActivity;
80+
81+
/**
82+
* Readonly property to get all properties of global field
83+
*/
84+
@property (nonatomic, copy, readonly) NSDictionary<NSString *, id> *properties;
85+
86+
/**
87+
* property to assign cache policy like CACHE_THEN_NETWORK, NETWORK_ELSE_CACHE, NETWORK_ONLY, etc.
88+
*/
89+
@property (nonatomic, assign) CachePolicy cachePolicy;
90+
//MARK: - Manually set headers
91+
/**---------------------------------------------------------------------------------------
92+
* @name Manually set headers
93+
* ---------------------------------------------------------------------------------------
94+
*/
95+
96+
/**
97+
Set a header for GlobalField.
98+
99+
//Obj-C
100+
[contentTypeObj setHeader:@"MyValue" forKey:@"My-Custom-Header"];
101+
//Swift
102+
contentTypeObj.setHeader("MyValue", forKey: "My-Custom-Header")
103+
@param headerValue The header key
104+
@param headerKey The header value
105+
*/
106+
- (void)setHeader:(NSString *)headerValue forKey:(NSString *)headerKey;
107+
/**
108+
Set a header for GlobalField.
109+
110+
//Obj-C
111+
[contentTypeObj addHeadersWithDictionary:@{@"My-Custom-Header": @"MyValue"}];
112+
113+
//Swift
114+
contentTypeObj.addHeadersWithDictionary(["My-Custom-Header":"MyValue"])
115+
116+
117+
@param headers The headers as dictionary which needs to be added to the application
118+
*/
119+
- (void)addHeadersWithDictionary:(NSDictionary<NSString *, NSString *> *)headers;
120+
/**
121+
Removes a header from this GlobalField.
122+
123+
//Obj-C
124+
[contentTypeObj removeHeaderForKey:@"My-Custom-Header"];
125+
126+
//Swift
127+
contentTypeObj.removeHeaderForKey("My-Custom-Header")
128+
129+
@param headerKey The header key that needs to be removed
130+
*/
131+
- (void)removeHeaderForKey:(NSString *)headerKey;
132+
133+
/**
134+
Retrieve the branch of the globalField.
135+
136+
//Obj-C
137+
Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" environmentName:@"ENVIRONMENT"];
138+
GlobalField *globalField = [stack GlobalField];
139+
[globalField includeBranch];
140+
141+
//Swift
142+
var stack:Stack = Contentstack.stackWithAPIKey("API_KEY", accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")
143+
var globalField:Asset = stack.GlobalField()
144+
globalField.includeBranch()
145+
146+
*/
147+
-(void)includeBranch;
148+
149+
/**
150+
Retrieve the schema of globalField.
151+
152+
//Obj-C
153+
Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" environmentName:@"ENVIRONMENT"];
154+
GlobalField *globalField = [stack GlobalField];
155+
[globalField includeGlobalFieldSchema];
156+
157+
//Swift
158+
var stack:Stack = Contentstack.stackWithAPIKey("API_KEY", accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")
159+
var globalField:Asset = stack.GlobalField()
160+
globalField.includeGlobalFieldSchema()
161+
162+
*/
163+
-(void)includeGlobalFieldSchema;
164+
165+
166+
/**
167+
Fetches an asset asynchronously provided asset UID
168+
169+
//Obj-C
170+
Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" environmentName:@"ENVIRONMENT"];
171+
//'ASSET_UID' is uid of an asset
172+
Asset* assetObj = [stack assetWithUID:@"ASSET_UID"];
173+
[assetObj fetch:^(ResponseType type, NSError *error) {
174+
//error if exists then use 'error' object for details
175+
}];
176+
177+
//Swift
178+
var stack:Stack = Contentstack.stackWithAPIKey("API_KEY", accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")
179+
//'ASSET_UID' is uid of an asset
180+
var assetObj:Asset = stack.assetWithUID("ASSET_UID")
181+
assetObj.fetch { (responseType, error!) -> Void in
182+
//error if exists then use 'error' object for details
183+
}
184+
185+
@param callback Completion block with params NSError
186+
*/
187+
188+
- (void)fetch:(void(^)(ResponseType type, NSError * BUILT_NULLABLE_P error))callback;
189+
190+
/**
191+
This method provides all the GlobalFields present in the stack.
192+
193+
//Obj-C
194+
[globalField fetchAll:^(ResponseType type,NSArray<GlobalField *> * BUILT_NULLABLE_P result,NSError * BUILT_NULLABLE_P error {
195+
//error for any error description
196+
//result for reponse data
197+
}];
198+
199+
//Swift
200+
globalField.fetchAll { (type, result, error) -> Void in
201+
//error for any error description
202+
//result for reponse data
203+
}
204+
205+
@param completionBlock block to be called once operation is done. The result data contains all the globalFields.
206+
*/
207+
- (void)fetchAll:(void (^) (ResponseType type,NSArray<GlobalField *> * BUILT_NULLABLE_P result,NSError * BUILT_NULLABLE_P error))completionBlock;
208+
@end
209+
210+
BUILT_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)