0
任何人都可以幫助這個最基本的快速內容的例子?試圖從Contentful(working)獲得響應,然後將結果實體映射到我的自定義結構。內容豐富,以迅速結構
Contentful swift文檔非常缺乏強制您在Git repose和複雜的示例之間跳躍,代碼片段僅涉及打印結果。
// 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
}
}