I am trying to convert a String
to NSURL
and my code for that is Below:
var url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=(self.latitude),(self.longitude)&destinations=(self.stringForDistance)&language=en-US"
println("This is String: (url)")
var remoteUrl : NSURL? = NSURL(string: url)
println("This is URL: (remoteUrl)")
And console prints something like this:
This is String: https://maps.googleapis.com/maps/api/distancematrix/json?origins=-34.4232722,150.8865837&destinations=-34.4250728,150.89314939999997|-34.4356434,150.8858692|-34.4250728,150.89314939999997|-34.4356434,150.8858692|-34.4250728,150.89314939999997|-34.4356434,150.8858692|-34.423234,150.88658899999996|-34.423234,150.88658899999996|-34.428251,150.899673|-34.4257439,150.89870229999997|-34.423234,150.88658899999996|-34.4257439,150.89870229999997|-34.425376,150.89388299999996&language=en-US
This is URL: nil
The remoteUrl
is nil
and I don't know what is the problem here.
After that I try sort String
like this:
var url : String = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=-34.4232722,150.8865837&destinations=-34.4250728,150.89314939999997&language=en-US"
println("This is String: (url)")
var remoteUrl : NSURL? = NSURL(string: url)
println("This is URL: (remoteUrl)")
And console prints:
This is String: https://maps.googleapis.com/maps/api/distancematrix/json?origins=-34.4232722,150.8865837&destinations=-34.4250728,150.89314939999997&language=en-US
This is URL: Optional(https://maps.googleapis.com/maps/api/distancematrix/json?origins=-34.4232722,150.8865837&destinations=-34.4250728,150.89314939999997&language=en-US)
This is working fine.
So can anybody please tell me what is wrong with my first case?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…