我正在尝试从输出中删除反斜杠,replacingOccurrences
不起作用。我想制作[String:String]
类型的字典,其中第二个字符串包含一个数组,而该数组内部包含一个字符串,即deviceID
。
let deviceIdArray = [membrs.deviceID!]
// str = str.replacingOccurrences(of: "\\", with: "") this is not working
var deviceIdDict: [String:String] = [:]
deviceIdDict = ["userData": "\(deviceIdArray)"]
print("my dictionary: \(deviceIdDict)")
输出:
my dictionary: ["userData": "[\"CEA2CE6B-EE43-43B6-A04D-5D11BD65A762\"]"]
答案 0 :(得分:0)
使用debugDescription
let dictString = deviceIdDict.debugDescription
print(dictString)
它将打印
["some": "more"]
您可以尝试dump
print("my dictionary: ")
dump(deviceIdDict)
它将像这样打印:
▿ 1 key/value pair
▿ (2 elements)
- key: "some"
- value: "more"