Contentful logo

Contentful Community

SwiftUI Example does not work

This code is generating this the following error (I’ve changed the spaceId and token for obvious reasons. What’s missing? There is either something not yet setup in contentful or there are not compatible with Xcode 12.3

import SwiftUI
import Contentful

let client = Client(spaceId: “<>”, accessToken: “<>”)

// id: the name of the content model that’s

func getArray(id: String, completion: @escaping([Entry]) -> ()) {
let query = Query.where(contentTypeId: id)

client.fetchArray(of: Entry.self, matching: query) { result in
    switch result {
    case .success(let array):
        DispatchQueue.main.async {
            completion(array.items)
            print(array.items)
        }
    case .failure(let error):
        print(error)
    }
}

2021-01-06 13:55:38.968555-0800 Globulon[15023:599683] [Contentful] Error: Errored: ‘GET’ https://cdn.contentful.com/spaces/dqub65thlope/environments/master/entries?content_type=Badges. An API error was returned that the SDK was unable to parse

Message: An API error was returned that the SDK was unable to parse

An API error was returned that the SDK was unable to parse