How to transform an array to a String in Swift?
本问题已经有最佳答案,请猛点这里访问。
我正在尝试将数组
我对在Swift中执行此操作的一些通用方法感兴趣,并且在可能的情况下,对某些功能样式感兴趣(因此无需使用for循环)。
1 2 3 | let array = [1, 2, 3, 4] let string = array.map(String.init).joinWithSeparator("") |
这将输出:
1 | 1 2 3 4 |
这里发生的是,首先在数组上
当您要求功能解决方案时:
1 2 3 | let s = ["h","e","l","l","o","","w","o","r","l","d","!"].reduce(""){"\($0)\($1)"} print(s) |
输出
1 | hello world! |
Otherweise做加盟。