gpt4 book ai didi

Swift 字典 [字符串 :String] to NSMutableDictionary?

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

我正在尝试创建并分配一个 Swift Dictionary类型 [String : String]SKSpriteNode属性(property)userData这需要 NSMutableDictionary .当我尝试这个时,我得到了错误:

'[String : String]' is not convertible to 'NSMutableDictionary'

谁能指出我正确的方向?

    // USER DATA
var dictionary: [String : String] = Dictionary()
dictionary["Orbit"] = orbit
dictionary["Zone"] = zone
dictionary["Impact"] = impact
var foundationDictionary = dictionary as NSMutableDictionary
neoSprite.userData = foundationDictionary

最佳答案

没有内置的转换。但是您可以使用 NSMutableDictionary 的带有字典的初始化程序:

var foundationDictionary = NSMutableDictionary(dictionary: dictionary)

关于Swift 字典 [字符串 :String] to NSMutableDictionary?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30354256/

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