2016-11-16 12 views
-2

このコードをSwift 2.3で実行していたのは問題ありませんでした。 Swift 3のコードを更新し始めたときに問題が発生しました。NSURLがSwift 3.0でnilを返す

{ 

var searchResults: [String]! 

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
     let correctedAddress = self.searchResults[indexPath.row].addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)   
let urlpath:NSString! = "https://maps.googleapis.com/maps/api/geocode/json?address=\(correctedAddress)" as NSString! 
let url = NSURL.init(string: urlpath as String) 

}

}   

私はiOSのプログラミングに非常に新しいですので、私の質問は非常に基本的なことがあり、私は以下のコードを使用するときに私のNSURLリターンはゼロ。私はグーグルで多くの答えを見つけることができませんでした。スウィフトは

答えて

1

構文の変化がたくさんある、あなたはこのようなあなたのURLを行うことができます -

let correctedAddress = "Delhi " //You can replace your address here 
let urlpath = "https://maps.googleapis.com/maps/api/geocode/json?address=\(correctedAddress)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) 
let url = URL(string: urlpath!) 
print(url!) 

結果: - Ajay.itが働いhttps://maps.googleapis.com/maps/api/geocode/json?address=Delhi%20

+0

感謝。 –

関連する問題