Client
open class Client
Client object for performing requests against the Contentful API.
-
The persistence integration which will receive delegate messages from the
Clientwhen newEntryandAssetobjects are created from data being sent over the network. Currently, these messages are only sent forclient.initialSync()andclient.nextSync. The relevant persistence integration lives at https://github.com/contentful/contentful-persistence.swift.Declaration
Swift
public var persistenceIntegration: PersistenceIntegration? -
init(spaceId:accessToken:clientConfiguration:sessionConfiguration:persistenceIntegration:contentModel:)Initializes a new Contentful client instance
Declaration
Swift
public init(spaceId: String, accessToken: String, clientConfiguration: ClientConfiguration = .default, sessionConfiguration: URLSessionConfiguration = .default, persistenceIntegration: PersistenceIntegration? = nil, contentModel: ContentModel? = nil)Parameters
spaceIdThe space you want to perform requests against.
accessTokenThe access token used for authorization.
clientConfigurationCustom Configuration of the Client.
sessionConfigurationThe configuration for the URLSession. Note that HTTP headers will be overwritten interally by the SDK so that requests can be authorized correctly.
persistenceIntegrationAn object conforming to the
PersistenceIntegrationprotocol which will receive messages about created/deleted Resources when callingsync()methods.Return Value
An initialized client instance.
-
Fetch the space this client is constrained to.
Declaration
Swift
@discardableResult public func fetchSpace(then completion: @escaping ResultsHandler<Space>) -> URLSessionDataTask?Parameters
completionA handler being called on completion of the request.
Return Value
The data task being used, which enables cancellation of requests, or
nilif the. Space was already cached locally -
Fetch the space this client is constrained to.
Declaration
Swift
@discardableResult public func fetchSpace() -> Observable<Result<Space>>Return Value
A tuple of data task and a signal for the resulting Space.
-
Fetch a collection of Entries from Contentful matching the specified query. This method does not specify the content_type in the query parameters, so the entries returned in the results can be of any type.
Declaration
Swift
@discardableResult public func fetchEntries(with query: Query, then completion: @escaping ResultsHandler<ArrayResponse<Entry>>) -> URLSessionDataTask?Parameters
queryThe Query object to match results againts.
completionA handler being called on completion of the request.
Return Value
The data task being used, enables cancellation of requests.
-
Fetch a collection of Entries from Contentful matching the specified query. This method does not specify the content_type in the query parameters, so the entries returned in the results can be of any type.
Declaration
Swift
@discardableResult public func fetchEntries(with query: Query) -> Observable<Result<ArrayResponse<Entry>>>Parameters
queryThe Query object to match results againts.
Return Value
A tuple of data task and an observable for the resulting array of Entry’s.
-
Fetch a collection of Assets from Contentful matching the specified query.
Declaration
Swift
@discardableResult public func fetchAssets(with query: AssetQuery, then completion: @escaping ResultsHandler<ArrayResponse<Asset>>) -> URLSessionDataTask?Parameters
queryThe Query object to match results againts.
completionA handler being called on completion of the request.
Return Value
The data task being used, enables cancellation of requests.
-
Fetch a collection of Assets from Contentful matching the specified query.
Declaration
Swift
@discardableResult public func fetchAssets(query: AssetQuery) -> Observable<Result<ArrayResponse<Asset>>>Parameters
queryThe Query object to match results againts.
Return Value
A tuple of data task and an observable for the resulting array of Assets.
-
Fetch a collection of Assets from Contentful matching the specified query.
Declaration
Swift
@discardableResult public func fetchMappedEntries(with query: Query) -> Observable<Result<MappedContent>>Parameters
queryThe Query object to match results againts.
Return Value
An Observable forr the resulting
MappedContentcontainer. -
Fetches all entries and includes matching the passed in
Query. The completion handler returned will return aMappedContentobject which contains an array ofAssets and a dictionary of ContentTypeId’s to arrays ofEntryModellabletypes of your own defining.Declaration
Swift
@discardableResult public func fetchMappedEntries(with query: Query, then completion: @escaping ResultsHandler<MappedContent>) -> URLSessionDataTask?Parameters
queryThe Query object to match results against.
completionA handler being called on completion of the request containing a
MappedContentinstance.Return Value
The data task being used, enables cancellation of requests.
-
Fetch a single Asset from Contentful.
Declaration
Swift
@discardableResult public func fetchAsset(id: String, completion: @escaping ResultsHandler<Asset>) -> URLSessionDataTask?Parameters
idThe identifier of the Asset to be fetched.
completionA handler being called on completion of the request.
Return Value
The data task being used, enables cancellation of requests.
-
Fetch a single Asset from Contentful.
Declaration
Swift
@discardableResult public func fetchAsset(id: String) -> Observable<Result<Asset>>Parameters
idThe identifier of the Asset to be fetched.
Return Value
A tuple of data task and a signal for the resulting Asset.
-
Fetch a collection of Assets from Contentful.
Declaration
Swift
@discardableResult public func fetchAssets(matching: [String: Any] = [:], completion: @escaping ResultsHandler<ArrayResponse<Asset>>) -> URLSessionDataTask?Parameters
matchingAn optional list of search parameters the Assets must match.
completionA handler being called on completion of the request.
Return Value
The data task being used, enables cancellation of requests.
-
Fetch a collection of Assets from Contentful.
Declaration
Swift
@discardableResult public func fetchAssets(matching: [String: Any] = [:]) -> Observable<Result<ArrayResponse<Asset>>>Parameters
matchingOptional list of search parameters the Assets must match.
Return Value
A tuple of data task and a signal for the resulting array of Assets.
-
Fetch the underlying media file as
Data.Declaration
Swift
public func fetchData(for asset: Asset, with imageOptions: [ImageOption] = []) -> Observable<Result<Data>>Parameters
assetThe
Assetwhich contains the relevant media file.imageOptionsAn optional array of options for server side manipulations.
Return Value
Tuple of the data task and a signal for the
Dataresult.
-
Fetch a single Content Type from Contentful.
Declaration
Swift
@discardableResult public func fetchContentType(id: String, completion: @escaping ResultsHandler<ContentType>) -> URLSessionDataTask?Parameters
idThe identifier of the Content Type to be fetched.
completionA handler being called on completion of the request.
Return Value
The data task being used, enables cancellation of requests.
-
Fetch a single Content Type from Contentful.
Declaration
Swift
@discardableResult public func fetchContentType(id: String) -> Observable<Result<ContentType>>Parameters
idThe identifier of the Content Type to be fetched.
Return Value
A tuple of data task and a signal for the resulting Content Type.
-
Fetch a collection of Content Types from Contentful.
Declaration
Swift
@discardableResult public func fetchContentTypes(matching: [String: Any] = [:], completion: @escaping ResultsHandler<ArrayResponse<ContentType>>) -> URLSessionDataTask?Parameters
matchingOptional list of search parameters the Content Types must match.
completionA handler being called on completion of the request.
Return Value
The data task being used, enables cancellation of requests.
-
Fetch a collection of Content Types from Contentful.
Declaration
Swift
@discardableResult public func fetchContentTypes(matching: [String: Any] = [:]) -> Observable<Result<ArrayResponse<ContentType>>>Parameters
matchingOptional list of search parameters the Content Types must match.
Return Value
A tuple of data task and a signal for the resulting array of Content Types.
-
Fetch a collection of Entries from Contentful.
Declaration
Swift
@discardableResult public func fetchEntries(matching: [String: Any] = [:], completion: @escaping ResultsHandler<ArrayResponse<Entry>>) -> URLSessionDataTask?Parameters
matchingOptional list of search parameters the Entries must match.
completionA handler being called on completion of the request.
Return Value
The data task being used, enables cancellation of requests
-
Fetch a collection of Entries from Contentful.
Declaration
Swift
@discardableResult public func fetchEntries(matching: [String: Any] = [:]) -> Observable<Result<ArrayResponse<Entry>>>Parameters
matchingOptional list of search parameters the Entries must match.
Return Value
A tuple of data task and a signal for the resulting array of Entries.
-
Fetch a single Entry from Contentful.
Declaration
Swift
@discardableResult public func fetchEntry(id: String, completion: @escaping ResultsHandler<Entry>) -> URLSessionDataTask?Parameters
idThe identifier of the Entry to be fetched.
completionA handler being called on completion of the request.
Return Value
The data task being used, enables cancellation of requests.
-
Fetch a single Entry from Contentful.
Declaration
Swift
@discardableResult public func fetchEntry(id: String) -> Observable<Result<Entry>>Parameters
idThe identifier of the Entry to be fetched.
Return Value
A tuple of data task and a signal for the resulting Entry.
-
Perform an initial synchronization of the Space this client is constrained to.
Declaration
Swift
@discardableResult public func initialSync(matching: [String: Any] = [:], completion: @escaping ResultsHandler<SyncSpace>) -> URLSessionDataTask?Parameters
matchingAdditional options for the synchronization.
completionA handler being called on completion of the request.
Return Value
The data task being used, enables cancellation of requests.
-
Perform an initial synchronization of the Space this client is constrained to.
Declaration
Swift
@discardableResult public func initialSync(matching: [String: Any] = [:]) -> Observable<Result<SyncSpace>>Parameters
matchingAdditional options for the synchronization.
Return Value
A tuple of data task and a signal for the resulting SyncSpace.
-
Perform a subsequent synchronization operation, updating the passed in
SyncSpacewith the latest content from Contentful.Calling this will mutate passed in SyncSpace and also return a reference to itself to the completion handler in order to allow chaining of operations.
Declaration
Swift
@discardableResult public func nextSync(for syncSpace: SyncSpace, matching: [String: Any] = [:], completion: @escaping ResultsHandler<SyncSpace>) -> URLSessionDataTask?Parameters
syncSpacethe relevant
SyncSpaceto perform the subsequent sync on.matchingAdditional options for the synchronization
completionA handler which will be called on completion of the operation
Return Value
The data task being used, enables cancellation of requests
-
Fetch the underlying media file as
UIImage.Declaration
Swift
public func fetchImage(for asset: Asset, with imageOptions: [ImageOption] = []) -> Observable<Result<UIImage>>Return Value
The signal for the
UIImageresult
View on GitHub
Client Class Reference