本文介绍了SwiftUI 中使用的反斜杠 (\) 是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在名为组合复杂接口"的 SwiftUI 的 Apple 教程中,该教程使用了一个反斜杠,它似乎不是字符串插值或转义字符.这是一行:
In the Apple tutorial for SwiftUI called "Composing Complex Interfaces", the tutorial uses a backslash that doesn't appear to be string interpolation or an escape character. This is the line:
ForEach(categories.keys.sorted().identified(by: \.self))这个反斜杠的目的是什么?
What is the purpose of this backslash?
下面是包含它的整个结构.
Below is the entire Struct that contains it.
struct CategoryHome: View { var categories: [String: [Landmark]] { .init( grouping: landmarkData, by: { $0.category.rawValue } ) } var body: some View { NavigationView { List { ForEach(categories.keys.sorted().identified(by: \.self)) { key in Text(key) } } .navigationBarTitle(Text("Featured")) } } } 推荐答案\.self 这是苹果添加的身份密钥路径:
\.self it's a identity keypath that apple added for:
添加引用身份密钥路径的能力,该路径引用它所应用到的整个输入值.
Add the ability to reference the identity key path, which refers to the entire input value it is applied to.
提案中的更多信息.
更多推荐
SwiftUI 中使用的反斜杠 (\) 是什么?
发布评论