gpt4 book ai didi

ios - 在 Swift-Json 中创建 NSMutableDictionary

转载 作者:行者123 更新时间:2023-11-30 12:19:05 24 4
gpt4 key购买 nike

我想使用 Swifty-Json 创建一个 NSMutableDictionary。我已经声明了这样的字典

   var arrTest = Array<JSON>()

var testDict : JSON = [:]

testDict.dictionaryObject?.updateValue(arrTest[0]["test"][indexPath.item]["xyz"], forKey: "abc")
  1. 现在我无法在此词典中设置ValueForKey。有人可以告诉我如何使用 SwiftyJson 创建 NSMutableDictionary 以及如何在该字典中插入、更新和删除值。

提前致谢

最佳答案

不要在 Swift 中使用 NSMutableDictionary,而是使用 Swift 内置类型 Dictionary。将其声明为 var 将使其可变。

您也不要将 updateValue 用于 Dictionary,只需使用下标:

var testDict : [String: AnyObject] = [:]
让 key = "abc"
let value = arrTest[0]["test"][indexPath.item]["xyz"]
testDict[key] = value

关于ios - 在 Swift-Json 中创建 NSMutableDictionary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45028534/

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