gpt4 book ai didi

ios - For循环基于Swift中的数组长度

转载 作者:IT王子 更新时间:2023-10-29 05:20:39 25 4
gpt4 key购买 nike

我一直在尝试获取数组的长度并使用该长度来设置我的循环应该执行的次数。这是我的代码:

  if notes.count != names.count {
notes.removeAllObjects()
var nameArrayLength = names.count
for index in nameArrayLength {
notes.insertObject("", atIndex: (index-1))
}
}

目前我只是得到错误:

Int does not have a member named 'Generator'

看起来是一个相当简单的问题,但我还没有找到解决方案。有什么想法吗?

最佳答案

您需要指定范围。如果你想包含 nameArrayLength:

for index in 1...nameArrayLength {
}

如果你想在 nameArrayLength 之前停止 1:

for index in 1..<nameArrayLength {
}

关于ios - For循环基于Swift中的数组长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26694742/

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