【问题标题】:How to convert multi String array to string array in swift [duplicate]如何在swift中将多字符串数组转换为字符串数组[重复]
【发布时间】:2019-11-22 05:53:37
【问题描述】:

变量名称:[[String]] = [["google"],["yahoo"],["facebook"]]

var convertNames:[String] = []

//如何将names多字符串数组转换为convertNames字符串数组

【问题讨论】:

    标签: swift multidimensional-array


    【解决方案1】:

    只需在names array 上使用flatMap(_:) 即可获得所需的结果,即

    let names = [["google"],["yahoo"],["facebook"]]
    
    let convertNames = names.flatMap{ $0 }
    print(convertNames) //["google", "yahoo", "facebook"]
    

    flatMap(_:) 中的详细信息请参阅链接 - https://developer.apple.com/documentation/swift/sequence/2905332-flatmap

    【讨论】:

      猜你喜欢
      • 2017-10-09
      • 2019-02-17
      • 2015-04-16
      • 2016-11-20
      • 1970-01-01
      • 1970-01-01
      • 2013-12-05
      • 2016-07-13
      相关资源
      最近更新 更多