Swift中的单引号字符

时间:2016-06-06 21:24:52

标签: swift

尝试在Swift的代码中添加单引号'字符,但它不断添加一个'',这必然是一个API调用。

我的代码是:

    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"

我需要使apiLocation变量看起来像:

$filter=geo.distance(Location, geography'POINT(lat, long)') le 0.5&searchMode=all&$count=true

让我知道谢谢。

2 个答案:

答案 0 :(得分:3)

对于单个引号使用转义字符\' = '和插值(\()),您可以在一个字符串中实现此操作。

let apiLocation = "$filter=geo.distance(Location, geography\'POINT(\(locationLat), \(locationLong))\' le 0.5&searchMode=all$count=true"

答案 1 :(得分:-2)

在Swift 5中,以下代码对我有用

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

输出

'

enter image description here