所以我试图在本地保存用户设备上的一些东西。当我打开崩溃它的应用程序时,我遇到了错误。错误发生在这块代码上 -
var allInformationByDate = [
"2016-08-13": DayData(sales: 0, doorsKnocked: 0, milesWalked: 0.00, hoursWorked: 0.00)
]
extension NSUserDefaults {
func setDayDataDictionary(dayData : [String: DayData], forKey key: String) {
var result = [String : [String: AnyObject]]()
for (key, value) in dayData {
result[key] = ["sales": value.sales, "doorsKnocked" : value.doorsKnocked, "milesWalked": value.milesWalked, "hoursWorked": value.hoursWorked]
}
self.setObject(result, forKey: key)
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
var allInfoByDateDefault = NSUserDefaults.standardUserDefaults()
if (allInfoByDateDefault.valueForKey("allInfoByDateRecord") != nil) {
allInformationByDate = (allInfoByDateDefault.valueForKey("allInfoByDateRecord") as? [String: DayData])!
}
}
func updateInterface() {
NSUserDefaults.standardUserDefaults().setDayDataDictionary(allInformationByDate, forKey: "allInfoByDateRecord")
}
}
" allInformationByDate =(allInfoByDateDefault.valueForKey(" allInfoByDateRecord")上的错误为?[String:DayData])!"专线说:
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
Will never be executed
原始问题,我已经实施了Vadian的建议:Swift: Cannot convert value of type '[String : DayData]' to expected argument type 'AnyObject?'
请帮忙!