【问题标题】:SwiftUI Group of Text + Link -> compiler errorSwiftUI Group of Text + Link -> 编译器错误
【发布时间】:2023-03-31 15:36:02
【问题描述】:

我正在尝试创建一个包含一些文本 + 粗体文本 + 链接的组,但我收到一个错误,我不确定为什么 ir 无法编译。不确定链接和文本是否不能在一起。有人对如何使这项工作有任何建议吗?

错误是:

编译器无法合理地对该表达式进行类型检查 时间;尝试将表达式分解为不同的子表达式

【问题讨论】:

  • 文本浏览量过多。如果可能的话,把它们分开

标签: ios compiler-errors swiftui


【解决方案1】:

您不能将 Text 和 Link 元素与 + 组合。

解决方案 1:

if let tcUrl = URL(string: "www.tc.com"), let policyUrl = URL(string: "www.policy.com") {
            Group {
                    Text("Byselecting ") + Text("Agree and sign up ").bold() + Text("below, I agree to the ")
                    Link(destination: tcUrl, label: {
                        Text("Terms & Conditions")
                    })
                    Text("and") + Text("")
                    Link(destination: policyUrl, label: {
                        Text("Privacy Policy")
                    })
            }
        }

解决方案 2:

if let tcUrl = URL(string: "www.tc.com"), let policyUrl = URL(string: "www.policy.com") {
            Group {
                    Text("Byselecting ") + Text("Agree and sign up ").bold() + Text("below, I agree to the ")
                HStack {
                    Link(destination: tcUrl, label: {
                            Text("Terms & Conditions")
                    })
                    Text("and")
                    Link(destination: policyUrl, label: {
                        Text("Privacy Policy")
                    })
                }
                    
            }
        }

【讨论】:

  • 谢谢@ufuk-köşker!是的,我也试过了,但我不能让它看起来像一个标签。即使设置对齐方式,它也会将行从组中断到 HStack =[
  • 我不明白你想怎么做。我英文不太好。如果你在设计申请中画出来并提交它会更好。
猜你喜欢
  • 2017-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-04
  • 1970-01-01
  • 2022-12-07
相关资源
最近更新 更多