2017-05-04 208 views
2

我知道,如果我想的Int秒的數組轉換爲String,我這樣做:轉換int數組以逗號分隔字符串

[0,1,1,0].map{"\($0)"}.reduce(""){$0+$1} 

,但我想不出我將如何轉換的Int s到一個逗號陣列分離String

+0

通過使用joinWithSeparator功能,你可以這樣做:https://開頭iosdevcenters。 blogspot.com/2016/04/array-in-swift.html –

回答

19

那麼你可以不喜歡它:

let formattedArray = ([0,1,1,0].map{String($0)}).joined(separator: ",") 
+0

VAR stringIds = 「」 如果讓tmpList = self.userList { stringIds =(tmpList.map {$ 0.id})。圖{字符串( $(0)}。joined(separator:「,」) } 用戶列表是我的自定義對象數組。 –

相關問題