Convert Swift Dictionary to String

后端 未结 4 585
日久生厌
日久生厌 2021-02-02 06:10

For testing and debugging I am trying to put the content of Dictionary to a String. But have no clue hows it going to achieve. Is it possible? If yes, how.

Dictionary is

4条回答
  •  情书的邮戳
    2021-02-02 06:31

    Dictionary to string with custom format:

    let dic = ["key1":"value1", "key2":"value2"]
    
    let cookieHeader = (dic.flatMap({ (key, value) -> String in
        return "\(key)=\(value)"
    }) as Array).joined(separator: ";")
    
    print(cookieHeader) // key2=value2;key1=value1
    

提交回复
热议问题