问题
I'm working through Apple's SwiftUI tutorial on building lists and navigation, and I can't seem to find any documentation for this List
initializer, or the identified(by:)
method of the Array
type:
struct LandmarkList: View {
var body: some View {
List(landmarkData.identified(by: \.id)) { landmark in
}
}
}
When I right-click on the List
initializer and click Jump to Definition
in Xcode, it takes me to this initializer which isn't right. When I do the same for the identified(by:)
method, it takes me to this strange file, which only has 13 lines and no mention of the identified(by:)
method:
I know Xcode is in beta, but where can I find the documentation for these mysterious bits of code? The tutorial has been great up to this point, but I'm not certain what this List
and Array
are doing.
回答1:
identified
is no more in use now. You may try below syntax.
List{
ForEach(landmarkData, id: \.id) { landmark in
Text(landmark.placeName)
}
}
来源:https://stackoverflow.com/questions/57020555/swiftui-list-initializer-with-identifiedby