这些是我通过网络调用填充的两个模型的示例。
int main()
{
randColor RandomOne;
RandomOne.setElement(0, "red");
RandomOne.setElement(1, "orange");
RandomOne.setElement(2, "yellow");
RandomOne.setElement(3, "blue");
RandomOne.setElement(4, "green");
RandomOne.setElement(5, "indigo");
RandomOne.setElement(6, "violet");
RandomOne.printColor();
return 0;
}
我正在尝试在列表中使用它们,但是int main()
{
randColor RandomOne;
const string colors[] = {"red", "orange", "yellow", "blue", "green", "indigo", "violet"};
for(int i = 0; i < 7; ++i) {
RandomOne.setElement(i, colors[i]);
}
RandomOne.printColor();
return 0;
}
不符合struct CombinedValueModel : Codable{
let identifiers: [ValueModel]
let descriptors: [ValueModel]
let amount: Double
}
struct ValueModel : Codable, Identifiable{
let id: String
let name: String?
let value: String
}
。模型包含CombinedValueModel
的列表。
Identifiable
我如何才能遍历这些值?
我尝试将id:\ .self赋予列表,但这使得CombinedValueModels
必须符合List(Model.values){ value in
Text("$\(value.amount, specifier: "%.2f")")
}
并导致实现您自己的“ ==” func。这导致ValueModel符合CombinedValueModel
和Hashable
。
有更简单的方法吗?
答案 0 :(得分:3)
您可以使用grep -r -i '(http|https)://[^/"]+.stage.domain.tld' .
属性(不包含在<Transfer
listStyle={{width: 500}}
/>
中)来遵守Identifiable
协议。使用id
手动为您的结构的每个实例生成唯一的标识符,如下所示:
CodingKeys