gpt4 book ai didi

ios - 如何在 Swift 中指示 for 循环的键是 NSString?

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

这里我有一个 for 循环。我知道我在其中存储了 NSStrings。如何指示 attributeName 的类型?我不想在循环内到处写 (relationshipName as NSString)

for attributeName in managedObject.entity.attributesByName.keys {
}

更新

如果我添加 [String] 和 for 循环声明,我会收到以下错误:

enter image description here enter image description here

更新

因为String也有问题

enter image description here enter image description here

最佳答案

您必须将 attributesByName 返回的字典转换为真正的键/值类型:

let attributes = managedObject.entity.attributesByName as [String: NSAttributeDescription]
for attributeName in attributes.keys {
// attributeName has the type String
// ...
}

let attributes = managedObject.entity.attributesByName as [NSString: NSAttributeDescription]
for attributeName in attributes.keys {
// attributeName has the type NSString
// ...
}

关于ios - 如何在 Swift 中指示 for 循环的键是 NSString?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24968282/

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