我遇到错误“无法将'Void'类型的值分配给'String吗?'” 我的代码
func showPhone(place: Place){
if let phone = place.phone {
var urlPhone: NSURL = URL(string: "TEL://\(phone)")! as NSURL
phoneValue.text = UIApplication.shared.open(urlPhone as URL, options: [:], completionHandler: nil)
}
else {
self.phoneContainer.isHidden = true
}
}
答案 0 :(得分:0)
原因:
您正在尝试将open(_:options:completionHandler:)
的结果分配为phoneValue's
text
。但是,方法open(_:options: completionHandler:)
不返回任何内容。这就是它给出错误的原因。
解决方案:
showPhone(place:)
方法应类似于
func showPhone(place: Place){
if let phone = place.phone {
phoneValue.text = phone
if let urlPhone = URL(string: "TEL://\(phone)") {
UIApplication.shared.open(urlPhone, options: [:], completionHandler: nil)
}
}
else {
self.phoneContainer.isHidden = true
}
}