Saving states using NSUserDefaults

Discussion in 'Mac Programming' started by xmax, Feb 25, 2009.

  1. macrumors member

    Joined:
    Jul 3, 2008
    #1
    I am binding check box value with shared user defaults controller in Interface Builder. I am registering defaults as well.
    but user defaults not working. it doesn't saves the status of check box.
    There is no plist file created at path /Library/Preferences for my application identifier.


    Thanks

    xmax
     
  2. macrumors member

    Joined:
    Jan 31, 2005
    Location:
    Sweden
    #2
    The plist file isn't created at /Library/Preferences, it is created at ~/Library/Preferences.

    Make sure that you use the controller key 'values' and then another name like e.g. 'CheckBoxValue' for the model key path.
     
  3. thread starter macrumors member

    Joined:
    Jul 3, 2008
    #3
    Sorry, But i have checked for ~/Library/Preferences.
    There is no any plist file created over there.
    can you tell me the steps from beginning for saving states of check box.
    I have given model key path for check box but i am not getting.
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    Your bindings might be setup wrong. Can you post a picture of IB with the bindings inspector selected for your checkbox?
     
  5. thread starter macrumors member

    Joined:
    Jul 3, 2008
    #5
    I am sending you my test application in attachment ?

    you can find what is the problem ?


    Thanks.
     

    Attached Files:

  6. thread starter macrumors member

    Joined:
    Jul 3, 2008
    #6
    I got what was the problem ?
    Actually i was quiting application from debugger. so it was not saving the state of check box. once i quit from Application Menu , it saved the state.
    So, I can understand that it will save the states on quiting the application, not on registering defaults.

    That concludes , to save the state we have to quit the application. or we can use the method synchronize or setValue:forKey to save the state when application is Running.

    am i correct ? what is correct method to save?


    Thanks.
     
  7. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #7
    Yes, synchronize is what you'd use to save it without waiting until restart. Most of the time you don't need this, just don't kill the app and let it terminate normally.
     

Share This Page