Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 有没有办法在Swift中以整数形式访问当前迭代计数?_Ios_Swift_Loops - Fatal编程技术网

Ios 有没有办法在Swift中以整数形式访问当前迭代计数?

Ios 有没有办法在Swift中以整数形式访问当前迭代计数?,ios,swift,loops,Ios,Swift,Loops,当我需要浏览项目列表并更新每个项目时,我通常会使用如下的for循环: for budget in arrayOfBudgets { budget.rent = enteredRentAmount } for index in 0..<arrayOfBudgets.count { arrayOfBudgets[index].rent = enteredAmounts[index] } 但是,当我需要在循环期间访问索引时,我会执行以下操作: for budget in arra

当我需要浏览项目列表并更新每个项目时,我通常会使用如下的for循环:

for budget in arrayOfBudgets {
   budget.rent = enteredRentAmount
}
for index in 0..<arrayOfBudgets.count {
   arrayOfBudgets[index].rent = enteredAmounts[index]
}
但是,当我需要在循环期间访问索引时,我会执行以下操作:

for budget in arrayOfBudgets {
   budget.rent = enteredRentAmount
}
for index in 0..<arrayOfBudgets.count {
   arrayOfBudgets[index].rent = enteredAmounts[index]
}
我知道解决这个问题很容易:

var index = 0
for budget in arrayOfBudgets {
   budget.rent = enteredAmounts[index]
   index += 1
}
但是我不喜欢在循环完成后,额外的两行代码和
索引
变量永远在那里,所以我希望有一种方法可以访问Swift中循环的迭代计数。

数组

for (index, budget) in arrayOfBudgets.enumerated() {
   budget.rent = enteredAmounts[index]
}

哇,太快了。非常感谢。