|
| 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