【发布时间】:2021-01-15 05:56:37
【问题描述】:
我是 swift 新手,并且正在使用多个字典的数组。所以我想改变一个特定键的值。请指导我如何实现它:
数组中的值:- [ { "开始":"凌晨 2:00", “结束”:“凌晨 2:00” }, { "开始":"凌晨 3:00", “结束”:“凌晨 3:00” } ]
待办事项:- 我想更改索引 1 处的键 Start 的值
代码:-
var aEntry = NSMutableArray.init()
for (index, type) in self.aEntry.enumerated(){
print("this is index value \(index)")
print("this is type value \(type)")
// Value of checkCurrentClickOfStart = 1
if index == Int(checkCurrentClickOfStart) {
let (item, newValue) = (index, "\(strHour)")
if 0 ..< self.aEntry.count ~= index {
(self.aEntry[index] as? NSMutableDictionary)?["Start"] = newValue
}
}
}
【问题讨论】:
-
你可以直接像aEntry[Int(checkCurrentClickOfStart)]["Start"] = "(strHour)"那样使用
-
@Anbu.Karthik 它说“'Any' 类型的值没有下标”
-
@hemant-garg: ` if 0 ..
-
停止使用 NS 类,改用 swift 类型
-
您可以在Swift Programming Language 书中阅读有关 swift 集合类型的信息
标签: ios arrays swift dictionary nsmutablearray