我有以下字典:
@State var ustasList: Dictionary<Usta, String> = [Usta: String]()
此视图:
ZStack(alignment: .top){
DropDown(defaultText: self.chosenUsta, font: self.fontStartAndButton, expand: false, options: self.ustaTypes){ opt in
print(self.ustasList)
}
.padding([.top, .leading, .trailing])
.zIndex(2)
List{
ForEach(self.ustasList.sorted(by: <), id: \.self){ item,typ in
Text(item)
}
}
}
但是此代码给我以下错误:Unable to infer complex closure return type; add explicit type to disambiguate
。我试图将ForEach行更改为
ForEach(self.ustaTypes, id: \.self){ item in
其中ustaTypes是一个简单的一维字符串数组,并且可以正常工作。那么为什么它不能与字典一起使用?