Swift iOS:EXC_BAD_在尝试通过键从任何对象获取值期间访问错误

Swift iOS:EXC_BAD_在尝试通过键从任何对象获取值期间访问错误,ios,swift,Ios,Swift,我有默认的字典: var activeLanguage:Dictionary<String,AnyObject> = [ "name":"English", "tag":"en",

我有默认的
字典

 var activeLanguage:Dictionary<String,AnyObject> = [
                                                    "name":"English",
                                                    "tag":"en",
                                                    "change_by_user":false,
                                                    "css_path":""
                                                    ]
我在几个客户端上进行了测试,但有一个应用程序在线崩溃:

self.activeLanguage["name"] = tempDict["name"] as? String ?? activeLanguage["name"]
完整堆栈跟踪:

0x00000001ae36bec8处的EXC\u错误\u访问内核\u无效\u地址

Thread : Crashed: com.apple.root.default-qos
0  libswiftCore.dylib             0x00000001004a17d0 swift_unknownRelease + 24
1  MyApp                       0x00000001000a4654 specialization <Swift.String with Swift.String : Swift.Hashable, Swift.AnyObject> of Swift._VariantDictionaryStorage.ensureUniqueNativeStorage <A : Swift.Hashable, B>(inout Swift._VariantDictionaryStorage<A, B>)(Swift.Int) -> (reallocated : Swift.Bool, capacityChanged : Swift.Bool) (MyAppPlugin.swift)
2  MyApp                       0x00000001000a2800 specialization <Swift.String with Swift.String : Swift.Hashable, Swift.AnyObject> of Swift._VariantDictionaryStorage.nativeUpdateValue <A : Swift.Hashable, B>(inout Swift._VariantDictionaryStorage<A, B>)(B, forKey : A) -> Swift.Optional<B> (MyAppPlugin.swift)
3  MyApp                       0x00000001000a1fa4 specialization <Swift.String with Swift.String : Swift.Hashable, Swift.AnyObject> of Swift.Dictionary.subscript.setter (A) -> Swift.Optional<B> (MyAppPlugin.swift)
4  MyApp                       0x00000001001a93e8 MyApp.WmConfigModel.build (MyApp.WmConfigModel)(Swift.AnyObject) -> () (WmConfigModel.swift:84)
5  MyApp                       0x00000001001ced54 MyApp.WmSettingsMgr.setSettings (MyApp.WmSettingsMgr.Type)(Swift.AnyObject) -> () (WmSettingsMgr.swift:29)
6  MyApp                       0x000000010009cce4 MyApp.MyAppPlugin.(setSettings (MyApp.MyAppPlugin) -> (ObjectiveC.CDVInvokedUrlCommand) -> ()).(closure #1) (<imports>)
7  MyApp                       0x0000000100099aa0 partial apply forwarder for reabstraction thunk helper from @callee_owned () -> (@unowned ()) to @callee_owned (@in ()) -> (@out ()) with unmangled suffix "102" (MyAppPlugin.swift:57)
8  MyApp                       0x0000000100099b10 partial apply forwarder for reabstraction thunk helper from @callee_owned (@in ()) -> (@out ()) to @callee_owned () -> (@unowned ()) with unmangled suffix "105" (MyAppPlugin.swift:57)
9  libdispatch.dylib              0x00000001978213ac _dispatch_call_block_and_release + 24
10 libdispatch.dylib              0x000000019782136c _dispatch_client_callout + 16
11 libdispatch.dylib              0x000000019782d40c _dispatch_root_queue_drain + 1152
12 libdispatch.dylib              0x000000019782e75c _dispatch_worker_thread3 + 108
13 libsystem_pthread.dylib        0x00000001979fd2e4 _pthread_wqthread + 816

是否可能
tempDict[“name”]
activeLanguage[“name”]
都是
nil
?@AaronBrager
activeLanguage[“name”]
不能是
nil
因为它有硬编码的默认值,
tempDict[“name”]
可能是
nil
它有硬编码的初始值,但是你不是说你以后要换吗?你能发那个密码吗?或者发布的代码是唯一更新的地方吗?@AaronBrager这是唯一一个我替换它的地方。也许最好的办法是创建常量字典并使用2个变量。如果让name=tempDict[“name”]{self.activeLanguage[“name”]=name},为什么不使用
Thread : Crashed: com.apple.root.default-qos
0  libswiftCore.dylib             0x00000001004a17d0 swift_unknownRelease + 24
1  MyApp                       0x00000001000a4654 specialization <Swift.String with Swift.String : Swift.Hashable, Swift.AnyObject> of Swift._VariantDictionaryStorage.ensureUniqueNativeStorage <A : Swift.Hashable, B>(inout Swift._VariantDictionaryStorage<A, B>)(Swift.Int) -> (reallocated : Swift.Bool, capacityChanged : Swift.Bool) (MyAppPlugin.swift)
2  MyApp                       0x00000001000a2800 specialization <Swift.String with Swift.String : Swift.Hashable, Swift.AnyObject> of Swift._VariantDictionaryStorage.nativeUpdateValue <A : Swift.Hashable, B>(inout Swift._VariantDictionaryStorage<A, B>)(B, forKey : A) -> Swift.Optional<B> (MyAppPlugin.swift)
3  MyApp                       0x00000001000a1fa4 specialization <Swift.String with Swift.String : Swift.Hashable, Swift.AnyObject> of Swift.Dictionary.subscript.setter (A) -> Swift.Optional<B> (MyAppPlugin.swift)
4  MyApp                       0x00000001001a93e8 MyApp.WmConfigModel.build (MyApp.WmConfigModel)(Swift.AnyObject) -> () (WmConfigModel.swift:84)
5  MyApp                       0x00000001001ced54 MyApp.WmSettingsMgr.setSettings (MyApp.WmSettingsMgr.Type)(Swift.AnyObject) -> () (WmSettingsMgr.swift:29)
6  MyApp                       0x000000010009cce4 MyApp.MyAppPlugin.(setSettings (MyApp.MyAppPlugin) -> (ObjectiveC.CDVInvokedUrlCommand) -> ()).(closure #1) (<imports>)
7  MyApp                       0x0000000100099aa0 partial apply forwarder for reabstraction thunk helper from @callee_owned () -> (@unowned ()) to @callee_owned (@in ()) -> (@out ()) with unmangled suffix "102" (MyAppPlugin.swift:57)
8  MyApp                       0x0000000100099b10 partial apply forwarder for reabstraction thunk helper from @callee_owned (@in ()) -> (@out ()) to @callee_owned () -> (@unowned ()) with unmangled suffix "105" (MyAppPlugin.swift:57)
9  libdispatch.dylib              0x00000001978213ac _dispatch_call_block_and_release + 24
10 libdispatch.dylib              0x000000019782136c _dispatch_client_callout + 16
11 libdispatch.dylib              0x000000019782d40c _dispatch_root_queue_drain + 1152
12 libdispatch.dylib              0x000000019782e75c _dispatch_worker_thread3 + 108
13 libsystem_pthread.dylib        0x00000001979fd2e4 _pthread_wqthread + 816
self.activeLanguage["name"] = tempDict["name"] as? String ?? activeLanguage["name"]