I'm getting the following error when trying to follow this tutorial:
Oh no something went wrong: A response for the QueryOn<Thing> did return successfully, but a serious error occurred when decoding the array of Thing.
Double check that you are passing Thing.self, and references to all other EntryDecodable classes into the Client initializer.
when using the following code to call contentful:
func fetch() {
let query = QueryOn<Thing>.where(field: .description, .exists(true))
client.fetchArray(of: Thing.self, matching: query) { (result: Result<ArrayResponse<Thing>>) in
switch result {
case .success(let things):
guard let firstThing = things.items.first else { return }
print(firstThing)
case .error(let error):
print("Oh no something went wrong: \(error)")
}
}
}
and i currently have two Things
added:
My Thing class looks like so:
final class Thing: EntryDecodable, FieldKeysQueryable {
enum FieldKeys: String, CodingKey {
case name, description
}
static let contentTypeId: String = "thing"
let id: String
let localeCode: String?
let updatedAt: Date?
let createdAt: Date?
let name: String
let description: String
public required init(from decoder: Decoder) throws {
let sys = try decoder.sys()
id = sys.id
localeCode = sys.locale
updatedAt = sys.updatedAt
createdAt = sys.createdAt
let fields = try decoder.contentfulFieldsContainer(keyedBy: Thing.FieldKeys.self)
self.name = try! fields.decodeIfPresent(String.self, forKey: .name)!
self.description = try! fields.decodeIfPresent(String.self, forKey: .description)!
}
}
Can anyone see what im missing?