我有以下JSON:
struct QuoteView: View {
var quote : QuoteDataModel
var body: some View {
VStack(alignment: .leading, spacing: 5) {
Text(quote.latin)
.font(.title)
if quote.expanded {
Group() {
Divider()
Text(quote.russian).font(.body)
}
}
}
}
}
...以及以下界面:
{
"items": [
{
"id": "123",
"title": "potatoes",
"category": "Fruit & Veg"
},
{
"id": "456",
"title": "custard",
"category": "Other"
}
]
}
当我导入JSON时,它可以工作,但是我被警告export interface ShoppingItems {
category: string;
id: number;
title: string;
}
。
我可以考虑界面中是否存在items数组,还是需要在界面外部进行说明?
答案 0 :(得分:3)
介绍单个项目的子界面
interface ShoppingItem {
category: string;
id: number;
title: string;
}
export interface ShoppingItems {
items: ShoppingItem[];
}