任何人都可以帮助这个最基本的快速内容示例吗?只是试图从 Contentful (working) 获得响应,然后将生成的实体映射到我的自定义结构。
内容丰富的 swift 文档非常缺乏,迫使您在 Git 休息和复杂示例之间跳转,并且代码片段仅涉及打印结果。
// Create structs that can be decoded from json
import Foundation
import Decodable
struct MyEntity {
let name: String
}
extension MyEntity {
static func decode(j: AnyObject) throws -> MyEntity {
return try Entity(
name: j => "nested" => "name"
)
}
}
// From other class, get the data (working) and then map it to struct objects
let client = Client(spaceIdentifier: "my_identifier", accessToken: "my_access_token")
client.fetchEntries(["content_type": "my_entity"]).1.next { result in
for item in result.items{
// Now what? item is not json so
// how to i convert it to an instance of MyEntity
}
}