swift - Getting elements from array of dictionary and save the keys as string, and values as string -
i have array of dictionaries of type <int,string>
this:
[14: "2", 17: "5", 6: "5", 12: "ali", 11: "0", 2: "4", 5: "it it", 15: "5", 18: "2", 16: "5", 8: "2", 13: "4", 19: "4", 1: "2", 4: "12-09-2017 - 9:52"]
i need keys alone , save them in string, , values alone , save them in string.
the results should that:
string key = "12,17,6,12,11,2,5,15,18,16,8,13,19,1,4" string values = "2,5,5,ali,0,4,it ti,5,2,5,2,4,4,2,12-09-2017 - 9:52"
a dictionary has keys
, values
property return keys/values (lazy) collection. values have join them:
let dict = [14: "2", 17: "5", 6: "5", 12: "ali", 11: "0", 2: "4", 5: "it it", 15: "5", 18: "2", 16: "5", 8: "2", 13: "4", 19: "4", 1: "2", 4: "12-09-2017 - 9:52"] let values = dict.values.joined(separator: ",") // ali,5,2,it it,5,0,4,5,4,4,2,12-09-2017 - 9:52,5,2,2
the keys integers , must converted strings first:
let keys = dict.keys.map(string.init).joined(separator: ",") // 12,17,14,5,15,11,13,16,19,2,18,4,6,8,1
the order unspecified, same keys , values.
Comments
Post a Comment