Global Fields
Global Fields
A Global field is a reusable field (or group of fields) that you can define once and reuse in any content type within your stack. This eliminates the need (and thereby time and efforts) to create the same set of fields repeatedly in multiple content types.
Example:
Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" environmentName:@"ENVIRONMENT"];
GlobalField *globalfield = [stack globalFieldWithName
:@"Global_field_uid"];
[globalfield fetch:^(ResponseType type, NSError * _Nullable error) {
}];fetch
The fetch method retrieves the details of the specified global field.
| Name | Type | Description |
|---|---|---|
| globalFieldUid (required) | String | UID of the Global field |
Example:
Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" environmentName:@"ENVIRONMENT"];
GlobalField *globalfield = [stack globalFieldWithName
:@"Global_field_uid"];
[globalfield fetch:^(ResponseType type, NSError * _Nullable error) {
}];find
The find method retrieves the details of all the global fields in the stack.
Example:
Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" environmentName:@"ENVIRONMENT"];
GlobalField *globalfield = [stack globalField];
[globalfield fetchAll:^(ResponseType type, NSArray<GlobalField *> * _Nullable result, NSError * _Nullable error){
}];includeBranch
The includeBranch method includes the branch details for single or multiple global fields.
Example:
Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" environmentName:@"ENVIRONMENT"];
GlobalField *globalfield = [stack globalField];
[globalfield includeBranch];
[globalfield fetchAll:^(ResponseType type, NSArray<GlobalField *> * _Nullable result, NSError * _Nullable error){
}];Note
- Information about Global fields can be retrieved by all users, regardless of their role or access level.
- If your Global field contains nested Global fields, they will appear as part of the schema in the API response.