0

I have a bunch of user defaults which I save and load on applicationWillTerminate/awakeFromNib. See below.

The objects are checkboxes (NSButton), Sliders (NSSlider) and one textfield (NSTextfield).

I´m on OS X. There is no problem on Checkboxes and Sliders.

Unfortunately I have a problem when loading the line with the NSTextfield:

[txtRemark setStringValue :[myDefaults stringForKey:kTxtRemark]];

For some reasons I´m getting a SIBART and I can´t figure out why :( No error when disabling this line.

My app throws an exception but I don´t know how to figure out what´s wrong.

A screenshot of the exception all the way down.

Thanks for help.

The keys are defines like this:

enter image description here

save myDefaults on applicationWillTerminate like this

  NSUserDefaults *myDefaults = [NSUserDefaults standardUserDefaults];
  [myDefaults setObject :[isAppointment state]         forKey:kIsAppointment];
  [myDefaults setObject :[boxForEver    state]         forKey:kBoxForEver];
  [myDefaults setObject :[boxMakeSound  state]         forKey:kBoxMakeSound];
  [myDefaults setObject :[tickTackFlag  state]         forKey:kTickTackFlag];
  [myDefaults setObject :[slideHour     intValue]      forKey:kSlideHour];
  [myDefaults setObject :[slideMin      intValue]      forKey:kSlideMin];
  [myDefaults setObject :[slideSec      intValue]      forKey:kSlideSec];
  [myDefaults setObject :[startAuto     state]         forKey:kStartAuto];
  [myDefaults setObject :[txtRemark     stringValue]   forKey:kTxtRemark];
  [myDefaults setObject :[volumeAdjust  intValue]      forKey:kVolumeAdjust];

load myDefaults on awakeFromNib like this

   NSUserDefaults *myDefaults = [NSUserDefaults standardUserDefaults];
   [isAppointment setState       :[myDefaults stringForKey:kIsAppointment]];
   [boxForEver    setState       :[myDefaults stringForKey:kBoxForEver]];
   [boxMakeSound  setState       :[myDefaults stringForKey:kBoxMakeSound]];
   [tickTackFlag  setState       :[myDefaults stringForKey:kTickTackFlag]];
   [slideHour     setIntValue    :[myDefaults stringForKey:kSlideHour]];
   [slideMin      setIntValue    :[myDefaults stringForKey:kSlideMin]];
   [slideSec      setIntValue    :[myDefaults stringForKey:kSlideSec]];
   [startAuto     setState       :[myDefaults stringForKey:kStartAuto]];
   [txtRemark     setStringValue :[myDefaults stringForKey:kTxtRemark]];
   [volumeAdjust  setIntValue    :[myDefaults stringForKey:kVolumeAdjust]];

enter image description here

Ronald Hofmann
  • 1,390
  • 2
  • 15
  • 26

1 Answers1

0

-stringForKey: is returning nil, presumably that default isn't actually set or registered. You can tell this because of the assertion message: "Invalid parameter not satisfying aString != nil"

Catfish_Man
  • 41,261
  • 11
  • 67
  • 84
  • mh, I tried several possibilities to find out how to get rid of the exception without success. Actually I don´t see what´s wrong. When saving the user defaults everything seems to work OK. What can I do? – Ronald Hofmann Dec 28 '12 at 11:57
  • You should split that line into two parts ( "get the value", and "set the string value"). Then sat a breakpoint on the first one and inspect the values in the debugger. – Catfish_Man Dec 28 '12 at 18:15