Swift: how can String.join() work custom types?

后端 未结 6 542
感动是毒
感动是毒 2020-12-30 02:43

for example:

var a = [1, 2, 3]    // Ints
var s = \",\".join(a)  // EXC_BAD_ACCESS

Is it possible to make the join function return \"1,2,3\

6条回答
  •  离开以前
    2020-12-30 03:37

    The simplest way is a variation of @BryanChen's answer:

    ",".join(a.map { String($0) } )
    

提交回复
热议问题