Hello,
I am calling the function fetchMappedEntries on my Client, and getting an Unexpectedly Unwrapped Optional on the Contentful extension of Decoder.
The following picture contains the crash itself. I can not log the contents of userInfo at this point
The only immediate thing that comes to mind is that I am not properly mapping my Contentful Content Model to my EntryDecodable class.
Here is my EntryDecodable class
import Contentful
import Interstellar
final class Article: EntryDecodable, ResourceQueryable {
static let contentTypeId: String = Constants.CONTENT_TYPE_ARTICLE
let sys: Sys
let title: String?
let shortDescription: String?
let dateAndTime: Date
let eventInfo: String?
let significance: String?
// let photos: [Link]?
let category: String?
let ranking: Int16
public required init(from decoder: Decoder) throws {
sys = try decoder.sys()
let fields = try decoder.contentfulFieldsContainer(keyedBy: Article.Fields.self)
self.title = try fields.decodeIfPresent(String.self, forKey: .title)
self.shortDescription = try fields.decodeIfPresent(String.self, forKey: .shortDescription)
self.dateAndTime = (try fields.decodeIfPresent(Date.self, forKey: .dateAndTime))!
self.eventInfo = try fields.decodeIfPresent(String.self, forKey: .eventInfo)
self.significance = try fields.decodeIfPresent(String.self, forKey: .significance)
// self.photos = try fields.decodeIfPresent(Array<Link>.self, forKey: .photos)
self.category = try fields.decodeIfPresent(String.self, forKey: .category)
self.ranking = (try fields.decodeIfPresent(Int16.self, forKey: .ranking))!
}
enum Fields: String, CodingKey {
case title, shortDescription, dateAndTime, eventInfo, significance, photos, category, ranking
}
}
This is my Content Model on Contentful:
I am aware that the photos is missing from the model, I tried to temporarily remove it to fix the problem to no avail.
If you have any ideas on how to fix this problem, either by helping me understand how the model in Swift maps to the model on Contentful better, or another means, please let me know.
Thanks!