试图实现类似 Tinder 的条款和条件之类的功能,但是我不知道如何使条款和隐私政策在 swift UI 中可点击

创建帐户或登录即表示您同意我们的条款和隐私政策
var body: some View {
Text(Constants.privacyText)
.applyCustomLabelTextProperties(size: size, kerning: 2)
.foregroundColor(color)
// .lineLimit(2)
+
Text(" ")
+
Text(Constants.terms).underline()
.foregroundColor(color)
// .onTapGesture {
// print("test")
// }
+
Text(" and ")
.foregroundColor(color)
+
Text(Constants.privacyPolicy).underline()
.foregroundColor(color)
}
}
Run Code Online (Sandbox Code Playgroud)
尝试在 Text() 上应用可点击的 .onTapGesture 并尝试添加一个按钮并将其连接到文本中,但也没有成功。
在 swiftyui 主体内,基于 news.urlToImage 值,我需要能够加载另一个视图(LOadRemoteImageView,这只是另一个接受可选 url 字符串来加载远程图像的视图),或者显示一个文本字符串“没有图片网址”。
按照下面的语法,它工作正常
if news.urlToImage == nil {
Text("no image url")
}else {
LoadRemoteImageView(withURL: news.urlToImage!).frame(width: 140, height: 140)
}
Run Code Online (Sandbox Code Playgroud)
然而,当尝试内联代码时,它失败了,intellisense 没有正确的错误消息
news.urlToImage == nil ? Text("no image") : LoadRemoteImageView(withURL: news.urlToImage!)
Run Code Online (Sandbox Code Playgroud)
如果 urlToImage: String 不是 nil,也尝试使用 map 来显示两个视图中的任何一个,但也失败了
news.urlToImage.map {
$0 != nil ? LoadRemoteImageView(withURL: $0) : Text("no image")
Run Code Online (Sandbox Code Playgroud)
}
我有一个通用的 JSON 解析器,可以解码数组
class JSONParserFromStruct {
typealias result<T> = (Result<[T], Error>) -> Void
func downloadList<T: Decodable>(of _: T.Type,
from data: Data,
completion: @escaping result<T>) {
do {
let decodedData: [T] = try! JSONDecoder().decode([T].self, from: data)
completion(.success(decodedData))
} catch {
completion(.failure(DataError.decodingError))
}
}
}
Run Code Online (Sandbox Code Playgroud)
捆绑包中的 Users.json 文件
{
"name": "Taylor Swift"
}
Run Code Online (Sandbox Code Playgroud)
像这样调用它:
func performRequest() {
let url = Bundle.main.url(forResource: "Users", withExtension: "json")!
let data = try! Data(contentsOf: url)
genericParser.downloadList(of: User.self, from: data) { result in
switch result {
case let …Run Code Online (Sandbox Code Playgroud)