【发布时间】:2020-06-02 15:17:00
【问题描述】:
我试图在这里获取文本以读取存储在Chat.Message.Incoming 的Content 枚举扩展中的privacyNotice 文本字符串的内容。以下内容此时无法编译:
private func renderPolicy(
isEnabled: Bool,
resource: ChosenResource<Notice>,
message: Chat.Message.Incoming,
) -> Node<NodeId> {
return Node(
component: Component.Message(
....
text: message.content.privacyNotice.text,
....
)
}
这是扩展名:
extension Chat.Message.Incoming {
public enum Content {
case text(message: String, style: Style)
case response(message: String)
case privacyNotice(text: String, resource: ChosenResource<Notice>)
}
}
在控制台中,当我遇到断点并输入 po message.content 时,我得到以下信息:
(lldb) po message.content
▿ Content
▿ privacyNotice : 2 elements
- text : "Privacy"
▿ resource : ChosenResource<Notice>
- generator : (Function)
那么当我输入po message.content.privacyNotice.text 时,我应该如何处理我得到的错误,这是我期望返回的Privacy,因此我可以在renderPolicy 函数中输入这个错误:
(lldb) po message.content.privacyNotice.text
error: <EXPR>:3:9: error: enum case 'privacyNotice' cannot be used as an instance member
message.content.privacyNotice.text
~~~~~~~~^~~~~~~
Chat.Message.Incoming.Content.
error: <EXPR>:3:31: error: value of type '(String, ChosenResource<Notice>) -> Chat.Message.Incoming.Content' has no member 'text'
message.content.privacyNotice.text
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~~~
TIA
【问题讨论】:
-
是否可以将您的
Content枚举更改为struct或class?