【发布时间】:2015-11-02 20:13:32
【问题描述】:
我在插入网址后尝试在 Swift 中创建 waze 链接,但出现致命错误。
我的代码:
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!)
}
错误是:
致命错误:在展开可选值时意外发现 nil
【问题讨论】:
-
错误发生在哪一行?
-
让 navAdd: NSURL? = NSURL(string:url)//这里是错误