Swift: 带参数的 NSURL 无效

Swift: NSURL with parameters is invalid

这是我与 UIActivityVieController 共享 Google 地图 link 的代码:

 if let myWebsite = NSURL(string: "http://maps.google.com/?q=<\(myLatitude)>,<\(myLongitude)>") {
        let objectsToShare = [alertMessage, myWebsite]
        let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
        //New Excluded Activities Code
        activityVC.excludedActivityTypes = [UIActivityTypeAirDrop, UIActivityTypeAddToReadingList]
        self.presentViewController(activityVC, animated: true, completion: nil)
    }

这个link是无效的;不调用 if 语句。我该如何解决这个问题?

您的 NSURL 格式应如下所示:

let myWebsite = NSURL(string: "http://maps.google.com/?q=\(myLatitude),\(myLongitude)")

要在字符串中使用字符串,您应该这样写

"My string \(otherString)";