Reputation: 127
Trying to add a single quote '
character in my code in Swift, but it's constantly adding a \'
and this is necessarily for an API Call.
My code is:
let locationLat = String(format: "%f", (currentLocation?.coordinate.latitude)!)
let locationLong = String(format: "%f", (currentLocation?.coordinate.longitude)!)
let apiLocation = "$filter=geo.distance(Location,geographyPoint" + "(" + locationLat + locationLong + ")) le 0.1"
I need to make the apiLocation variable look like:
$filter=geo.distance(Location, geography'POINT(lat, long)') le 0.5&searchMode=all&$count=true
Let me know thanks.
Upvotes: 7
Views: 9936
Reputation: 11544
In Swift 5, below code worked for me
let myText = #"'"#
print(myText)
Output
'
Upvotes: 1
Reputation: 2447
Using escape character for single quotes \'
= '
and interpolation (\()
)for variables you can achieve this in one string.
let apiLocation = "$filter=geo.distance(Location, geography\'POINT(\(locationLat), \(locationLong))\' le 0.5&searchMode=all$count=true"
Upvotes: 4