gpt4 book ai didi

arrays - 在 Swift 中混合数组、元组和闭包的问题

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

<分区>

我正在尝试管理一个 (String, closure) 元组数组。

数组定义为:

var menuItems: [(title: String, closure: () -> Void)] = []

现在我正在尝试向其中添加项目:

// 1. Adding directly a tuple fails with "Missing argument for parameter 'closure' in call"
menuItems.append((title: "any", closure: {}))

// 2. Using let works
let item: (title: String, closure: () -> Void) = (title: "any", closure: {})
menuItems.append(item)

// 3. Using var fails with "Missing argument for parameter 'closure' in call"
var item: (title: String, closure: () -> Void) = (title: "any", closure: {})
menuItems.append(item)

任何解释或添加项目的更好方法将不胜感激。

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