使用未申报类型的“解码的” /“可编码的”斯威夫特3
问题描述:
所以我与苹果的Using JSON with Custom Types教程进行操作,请通过故事板,和我碰到一个错误尝试以下操作:使用未申报类型的“解码的” /“可编码的”斯威夫特3
struct GroceryStoreService: Decodable {
let name: String
let aisles: [Aisle]
struct Aisle: Decodable {
let name: String
let shelves: [Shelf]
struct Shelf: Decodable {
let name: String
let product: GroceryStore.Product
}
}
}
只有我收到错误:
Use of undeclared type Decodable
- 与Codable相同。
我检查了其他SO问题,尝试清理和构建,戳穿构建阶段,迄今为止没有得到该排序的运气。
答
您需要Xcode 9和Swift 4才能使用Codable。 最佳的文字我已经看到它至今:https://medium.com/swiftly-swift/swift-4-decodable-beyond-the-basics-990cc48b7375
如果你有一个样品JSON,您可以使用此JSON斯威夫特可编码转换器:http://danieltmbr.github.io/JsonCodeGenerator/
难道你需要的Xcode 9 /斯威夫特4解码/可编码? – rmaddy
是的,它只能在Swift 4中使用。 – Moritz
哦,该死的它是新的?谢谢,我会升级。 – SQLiteNoob