ios - NSUserDefaults returning nil -


After

Try to save an object to NSUserDefaults and then remove the same object.

  // Raw: Enter any object! = Defaults.valueForKey ("testKey") // go to data = such as raw NSData // // self.Report = NSKeyedUnarchiver.unarchiveObjectWithData (Data) DayReport // // println (Report.Day) Report.Day = "Mon" Go to data = NSKeyedArchiver.archivedDataWithRootObject (self.Report) println (data) defaults.setObject (data, forKey: "testKey") defaults.synchronize ()  

This piece of code The object NSUserDefaults has been encoded into NSDT in saving. Déporte is that type of report

But when I switch the comment sections, the upper part of the code is not commented and the lower part is , let var = (zero) and the program crashes. Why?

DayReport is NSCoding protocol.

update

  defaults.setObject (data, forKey :: "testKey")> I added this default defaults.synchronize () println (defaults. ObjectForKey ("testKey"))  

and prints it from zero, so it is not well left but the data is not zero.

You should not use .valueForKey ("testKey") Because it is using KVC to try to get an important that does not exist.

Instead you should use .objectForKey ("testkey") .


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -