<分区>
我正在尝试运行我的 SwiftUI
演示,但我遇到了奇怪的编译器问题:
'Color' is not convertible to 'Color?'
Unable to infer complex closure return type; add explicit type to disambiguate
struct LandmarkRow: View {
var landmark: Landmark
var body: some View {
HStack {
landmark.image(forSize: 50)
Text(landmark.name)
Spacer()
if landmark.isFavorite {
Image(systemName: "star.fill")
.imageScale(.medium)
.foregroundColor(.yellow) // Here 'Color' is not convertible to 'Color?'
}
}
}
}
struct LandmarkList: View {
@State var showFavoritesOnly = true
var body: some View {
NavigationView {
List {
Toggle(isOn: $showFavoritesOnly) {
Text("Favorites only")
}
ForEach(landmarkData) { landmark in // Here Unable to infer complex closure return type; add explicit type to disambiguate
if !self.showFavoritesOnly || landmark.isFavorite {
NavigationButton(destination: LandmarkDetail(landmark: landmark)) {
LandmarkRow(landmark: landmark)
}
}
}
.navigationBarTitle(Text("Landmarks"))
}
}
}
}