0
我尝试使链接在Swift中插入URL后出现致命错误。NSURL致命错误
我的代码:
let newName:String = closest.name.stringByReplacingOccurrencesOfString(" ", withString: "&", options: NSStringCompareOptions.LiteralSearch, range: nil)
print(closest.name)
print(newName)
let url:String = "waze://?q=\(newName)"
print(url)
let navAdd: NSURL? = NSURL(string:url)// here is the error
let wazeApp: NSURL? = NSURL(string: "http://itunes.apple.com/us/app/id323229106")!
print(navAdd)
if(true){
UIApplication.sharedApplication().openURL(navAdd!)
}else{
UIApplication.sharedApplication().openURL(wazeApp!)
}
和错误是:
fatal error: unexpectedly found nil while unwrapping an Optional value
错误发生在哪一行? – Aaron
让navAdd:NSURL? = NSURL(string:url)//这里是错误 – Tzahi