SwiftUI List initializer with identified(by:)

烂漫一生 提交于 2020-07-22 06:02:28

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!