escape dictionary key double quotes when doing println dictionary item in Swift

前端 未结 5 767
鱼传尺愫
鱼传尺愫 2020-11-30 08:51

I\'ve been playing around with Swift, and just came across an issue. I have the following Dictionary in:

var locations:Dictionary

        
5条回答
  •  情话喂你
    2020-11-30 09:09

    You can use string concatenation instead of interpolation:

    println("Some words " + dict["key"]! + " some more words.")
    

    Just mind the spaces around the + signs.

    UPDATE:

    Another thing you can do is to use string format specifiers the same way how it was done back in the objective-c days:

    println( String(format: "Some words %@ some more words", dict["1"]!) )
    

提交回复
热议问题