Saving NSDate error in Swift 3 and iOS 10

心不动则不痛 提交于 2019-12-13 07:11:02

问题


I believe this is a bug introduced in the new stack probably Swift 3 / iOS 10. I am running on XCode8 / Swift3 / iPhone 7 (Simulator) / ios 10.0 I have not found any related report of it.

  1. set the value

    let dt : Date? = Date()
    UserDefaults.standard.set(dt, forKey: "test-date")
    
  2. Get the value

    let dt = UserDefaults.standard.object(forKey: "test-date")
    if dt == nil {
      return false
    }
    else {
      let date = dt! as Date // FAILED
    }
    

The failed message is:

Could not cast value of type '__NSCFData' (0x10fa08500) to 'NSDate' (0x10fa08f00).

Not sure how the object is converted to NSData instead of NSDate.

来源:https://stackoverflow.com/questions/39515942/saving-nsdate-error-in-swift-3-and-ios-10

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!