【发布时间】:2017-06-20 12:54:57
【问题描述】:
我已经搜索过了,真的,在这里问一个问题是我最后的手段......老实说,但请随意对我投反对票,因为“我不得不问”......! 现在开始做事了……
我有一本包含两层“dict > 键”的字典,就是这样!但无论出于何种原因,我似乎无法获得“三”的价值。我这里哪里出错了?
print(mainDict)
/*
["keys": {
one = "one...";
two = 2;
three = "three"; // need this one!
}]
*/
let sub = mainDict["keys"]
print(sub as Any)
/*
Optional({
one = "one...";
two = 2;
three = "three";
})
*/
太棒了!到目前为止一切都很好......但是:
let keyThree = mainDict["three"]
print(keyThree as Any)
// nil
let keyThree = sub["three"]
// Type 'NSObject?' has no subscript members
WTH? ...尝试:
【问题讨论】:
-
请分享字典的初始化
-
@AmrElAdawy:
func makeThisPossible(mainDict: [String : NSObject]) -
分享您最初设置值的代码
-
@Russell:你的意思是
let mainDict = (userInfo as? [String: NSObject])!?,调用的函数是optional func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String : Any])
标签: swift xcode macos swift3 macos-sierra