【问题标题】:Return a multiple array in array in a Swift 3 function在 Swift 3 函数中返回数组中的多个数组
【发布时间】:2017-06-22 07:33:05
【问题描述】:

我对返回数组中的值有疑问,

var data = [[Int](),[Int]()]

如何在函数中返回数据?

func test() ->[[Int](),[Int]()] // this giving me error {

}

如何在 Swift 中返回单个数组中的多个数组?

【问题讨论】:

  • 有趣的测试()-> [[Int]] { }
  • 返回一个touple怎么样? func test() -> ([Int], [Int]){}

标签: arrays swift function swift3


【解决方案1】:

[[Int](),[Int]()] 的类型为[[Int]](与Array<Array<Int>> 相同), 即一个数组,其元素是Int的数组:

func test() -> [[Int]] {
    let data = [[Int](),[Int]()]
    return data
}

【讨论】:

    猜你喜欢
    • 2015-12-24
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    • 2021-08-14
    • 2021-05-13
    • 2019-03-30
    相关资源
    最近更新 更多