其他分享
首页 > 其他分享> > SwiftUI encode URL string All In One

SwiftUI encode URL string All In One

作者:互联网

SwiftUI encode URL string All In One

Swift encode URL Chinese Unicode

黄瓜 => %E9%BB%84%E7%93%9C

const str = `黄瓜`;

encodeURI(str)
// '%E9%BB%84%E7%93%9C'

encodeURIComponent(str)
// '%E9%BB%84%E7%93%9C'

dead code ❌

//
//  OutLinkView.swift
//  Vegetable
//
//  Created by xgqfrms on 2022/5/18.
//

import SwiftUI

struct OutLinkView: View {
  var vegetable: VegetableModel;
  init(_ vegetable: VegetableModel) {
    self.vegetable = vegetable;
  }
  var body: some View {
    GroupBox {
      HStack {
        Text("数据来源")
        Spacer()
        // Link("维基百科", destination: URL(string: "https://zh.wikipedia.org/wiki/\(vegetable.title)")!)
        // Link("维基百科", destination: URL(string: "https://zh.wikipedia.org/wiki/黄瓜")!)
        Link("维基百科", destination: URL(string: "https://zh.wikipedia.org/wiki/%E9%BB%84%E7%93%9C")!)
        Image(systemName: "arrow.up.right.square")
      }
    }
  }
}

struct OutLinkView_Previews: PreviewProvider {
  static var previews: some View {
    OutLinkView(VegetableData[0])
      .previewLayout(.sizeThatFits)
  }
}

solution ✅


refs


Flag Counter

©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载

标签:string,URL,E7%,vegetable,84%,SwiftUI,93%,encode
来源: https://www.cnblogs.com/xgqfrms/p/16284528.html