override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let firstPart = URL(string: "https://www.kiva.org/lend/")
let secondPart = loans[indexPath.row].id
let result = firstPart + secondPart
UIApplication.shared.openURL(result as URL)
}
错误:二进制运算符不能应用于两个url操作数
答案 0 :(得分:3)
您应该将字符串相互追加并将其作为URL。
let urlString = "https://www.kiva.org/lend/" + loans[indexPath.row].id
let url = URL(string: urlString)
答案 1 :(得分:0)
我“弄坏了我的头”,但我修正了我的错误
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let firstPart = URL(string: "https://www.kiva.org/lend/\(loans[indexPath.row].id)")
UIApplication.shared.openURL(firstPart!)