Convert an array of Ints to a comma separated string
25,080
Well you can do it like :
let formattedArray = ([0,1,1,0].map{String($0)}).joined(separator: ",")
Author by
Lauren Eccles
Updated on May 04, 2020Comments
-
Lauren Eccles about 4 years
I know that if I want to convert an array of
Int
s to aString
, I do this:[0,1,1,0].map{"\($0)"}.reduce(""){$0+$1}
but I cannot figure out how would I convert an array of
Int
s to a comma separatedString
-
Urvish Modi over 6 yearsvar stringIds = "" if let tmpList = self.userList { stringIds = (tmpList.map{$0.id}).map{String($0)}.joined(separator: ",") } user list is my custom objects array.
-
WestCoastProjects about 4 yearsYou don't actually need the parens around the array/map
[0,1,1,0].map{String($0)}.joined(separator: ",")
is fine -
asanli about 3 yearsYou are my Steve Jobs