我知道网址有效
网址是 不是 有效。您 不 知道自己以为所知道的。监听运行时。它比您了解的更多。
只需单独尝试以下代码(例如,在操场上):
var urlString = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=37.7873589,-122.408227&radius=4000&types=aquarium|art_gallery&key=YOURKEY"let url = NSURL(string:urlString)
url是零。那就是你的问题。您不能强行打开
nil;如果这样做,您将崩溃。
确认这一点后,您可以开始考虑 为什么 URL无效。(很明显为什么会这样。)学会相信编译器和运行时是成功编程的 关键 。
提示:这样 形成您的URL,一切都很好:
let url2 = NSURL(scheme: "https", host: "maps.googleapis.com", path: "/maps/api/place/nearbysearch/json?location=37.7873589,-122.408227&radius=4000&types=aquarium|art_gallery&key=YOURKEY")
你为什么这么认为呢?查看文档,看看此初始化程序可以为您做什么…



