vkrishnan23
vkrishnan23

Reputation: 127

Single quote character in Swift

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

Answers (2)

Shelly Pritchard
Shelly Pritchard

Reputation: 11544

In Swift 5, below code worked for me

let myText = #"'"#
print(myText) 

Output

'

enter image description here

Upvotes: 1

NSGangster
NSGangster

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

Related Questions