gpt4 book ai didi

arrays - Array of arrays of typealias 表达式类型不明确,没有更多上下文

转载 作者:搜寻专家 更新时间:2023-11-01 06:07:10 28 4
gpt4 key购买 nike

我正在尝试创建 typealias 对象的数组数组 - 但我收到“表达式类型不明确,没有更多上下文”编译错误。这是我的代码:

typealias TestClosure = ((message: String)->())
var testArray = [[TestClosure]](count: 4, repeatedValue: nil)

我在这里错过了什么?

更新:

事实证明,当数组数组是一个可选数组时,它会编译:

var testArray = [[TestClosure]?](count: 4, repeatedValue: nil)

但是 - 我想确保初始数组将包含实际的空数组。我该怎么做?

最佳答案

swift 2

使用repeatedValue 创建空数组:

var testArray = Array(count: 4, repeatedValue: [TestClosure]())

swift 3

语法变了,但思路是一样的:

var testArray = Array(repeating: [TestClosure](), count: 4)

关于arrays - Array of arrays of typealias 表达式类型不明确,没有更多上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34577194/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com