【问题标题】:Access GrandChild of Multidimensional Array in Swift在 Swift 中访问多维数组的 GrandChild
【发布时间】:2016-04-20 07:50:02
【问题描述】:

我有一个多维数组。好像是[["1","2","3"]],我怎么才能访问"1"

要了解更多细节...

lazy var data : [[NSURL]] = {

        var array = [[NSURL]]()

        if array.count == 0 {

            var index = 0
            var section = 0

            for image in images {
                if array.count <= section {
                    array.append([NSURL]())
                }
                array[section].append(image)

                index += 1

            }
        }
        return array
    }()

使用print(data),我可以访问:

[["firstUrl", "secondUrl", "thirdUrl"]]

如何访问"first"

【问题讨论】:

  • 这样:array[0][0]
  • @AlexanderDoloz 添加它作为答案,我接受它:)

标签: ios arrays swift multidimensional-array


【解决方案1】:

你可以这样做:array[0][0]

【讨论】:

    【解决方案2】:

    例如这样枚举:

    var dict = [["1","2","3"]]
    
    for (index, item) in dict.enumerate() {
    //hear you enumerate []
        for (index, item) in item.enumerate() {
            //hear you enumerate ["1","2","3"]
            print("Found \(item) at position \(index)")
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-13
      • 2019-06-12
      相关资源
      最近更新 更多