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:
let stack = Contentstack.stack(apiKey: "<API_KEY>", deliveryToken: "<DELIVERY_TOKEN>", environment: "<ENVIRNOMENT>")
stack.globalField().find{(result: Result<ContentstackResponse<GlobalFieldModel>, Error>, responseType) in
switch result {
case .success(let model):
case .failure(let error):
}
}fetch
The fetch method retrieves the data of the specified global field.
| Name | Type | Description |
|---|---|---|
| globalFieldUid (required) | String | UID of the Global field |
Example:
let stack = Contentstack.stack(apiKey: "<API_KEY>", deliveryToken: "<DELIVERY_TOKEN>", environment: "<envirnoment>")
stack.globalField(uid: globalFieldUid).fetch{ (result: Result<GlobalFieldModel, Error>, _) in
switch result {
case .success(let model):
case .failure(let error):
}
}find
The find method retrieves the data of the all the global fields of the stack.
Example:
let stack = Contentstack.stack(apiKey: "<API_KEY>", deliveryToken: "<DELIVERY_TOKEN>", environment: "<ENVIRNOMENT>")
stack.globalField().includeBranch().find{(result: Result<ContentstackResponse<GlobalFieldModel>, Error>, responseType) in
switch result {
case .success(let model):
case .failure(let error):
}
}includeBranch
The fiincludeBranchd method includes the branch details for single or multiple global fields
Example:
let stack = Contentstack.stack(apiKey: "<API_KEY>", deliveryToken: "<DELIVERY_TOKEN>", environment: "<ENVIRNOMENT>")
stack.globalField().includeBranch().find{(result: Result<ContentstackResponse<GlobalFieldModel>, Error>, responseType) in
switch result {
case .success(let model):
case .failure(let 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.