我似乎無法在其他問題上找到解決方案。Swift Locksmith:致命錯誤:意外地發現零,同時展開一個可選值
我正在使用Swift Locksmith(https://github.com/matthewpalmer/Locksmith)庫。
以下是我有:
let dictionary = Locksmith.loadDataForUserAccount("AppData")
當我打印出來的字典,我得到:
Optional(["username": test, "password": test123])
然而,當我嘗試分配這些值變量傳遞長我似乎他一個事故和出現錯誤:
fatal error: unexpectedly found nil while unwrapping an Optional value
我試圖賦予它像這樣:
username = dictionary["username"]
哪位告訴我:
Type '[String : AnyObject]?' has no subscript members
我試圖用.stringValue像這樣:
dictionary["username"].stringValue
的Xcode然後叫我「修復它」,所以我點擊修復按鈕然後xcode給了我這個:
username = dictionary!["username"]!.stringValue
tl; dr所以,我的問題
如何從字典(鑰匙串項目)中獲取用戶名和密碼並將其分配給變量,以便我可以將它們傳遞給新視圖?
同樣的錯誤:致命錯誤:意外地發現零,同時展開一個可選值 – JamesG