SwiftUI 中使用的反斜杠 (\) 是什么?

编程入门 行业动态 更新时间:2024-10-10 21:22:51
本文介绍了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 中使用的反斜杠 (\) 是什么?

本文发布于:2023-11-27 22:44:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639910.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:斜杠   SwiftUI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!