swetha
swetha

Reputation: 152

Getting nil when adding urlpath to NSUrl in Swift Programming

mapServerRequest="Midtown, New York, NY, USA"

var mapAddress:NSString=mapServerRequest

     println(mapAddress)
var urlpath=NSString(format: "http://maps.googleapis.com/maps/api/geocode/json?address=%@", mapAddress)
     println(urlpath)
var url = NSURL.URLWithString(urlpath)
    println(url)

Upvotes: 0

Views: 118

Answers (1)

Cornelius
Cornelius

Reputation: 4264

You should URL encode your mapAddress:

mapAddress.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLPathAllowedCharacterSet())

Upvotes: 2

Related Questions