Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

confirmation about NSUserDefaults

kevincobain2000kevincobain2000 Posts: 40New Users
edited November 2012 in iOS SDK Development
Hi, Just need a green light from experts opinion about using NSUserData

If I need to store the user data with 6 keys NSUserData is the way to go right ? Example, User's preference settings page "remembering user's option for 6 switches".
Post edited by kevincobain2000 on
Mountain Lion | xcode 4.5
http://www.jaist.ac.jp/~s1010205

Replies

  • Duncan CDuncan C Posts: 9,114Tutorial Authors, Registered Users @ @ @ @ @ @ @
    You mean NSUserDefaults? There is a key NSUserData that you can use to store a (read-only) string in your app's info.plist file, but I only found that when searching to see if NSUserData really existed. I've never used it myself.

    Be precise when asking questions. It wastes a lot of time if you use the wrong terms for things.

    It sounds like you want to save read/write data.

    Indeed, if you want to store a moderate number of settings that aren't changing many times a second, NSUserDefaults is a good choice.
    Regards,
    Duncan C
    WareTo

    widehead.gif
    Animated GIF created with Face Dancer, available for free in the app store.

    I'm available for one-on-one help at CodeMentor
  • kevincobain2000kevincobain2000 Posts: 40New Users
    Thanks a lot Duncan, I am sorry it was NSUserDefaults. I have a bad habit of xcode's intelli code sense !

    *Edit:
    Subject Edited
    Mountain Lion | xcode 4.5
    http://www.jaist.ac.jp/~s1010205
  • kevincobain2000kevincobain2000 Posts: 40New Users
    Sorry Duncan to bring this up from the dead.
    I have stored data in NSUserDefaults, and have a further question upon updating the app. So when the app is going to updated, I do the same way build and then connect to itunes connect and follow from there. In this case the existing NSUserDefaults is untouched right ? As in the simulator it is untouched when i make changes to the code (unless I reset contents and settings).

    Also, Is it a good iPhone programming practice to also save the NSUserDefaults to a plist ??
    Mountain Lion | xcode 4.5
    http://www.jaist.ac.jp/~s1010205
  • martol1nimartol1ni Posts: 42Registered Users
    Whether you would like to load the NSUserDefaults from a plist if it's gone is completely up to you. The existing NSUserDefaults will be untouched if not explicitly cleared by the user.
  • kevincobain2000kevincobain2000 Posts: 40New Users
    Cool Thanks martol1ni for the confirmation
    Mountain Lion | xcode 4.5
    http://www.jaist.ac.jp/~s1010205
  • Duncan CDuncan C Posts: 9,114Tutorial Authors, Registered Users @ @ @ @ @ @ @

    Sorry Duncan to bring this up from the dead.
    I have stored data in NSUserDefaults, and have a further question upon updating the app. So when the app is going to updated, I do the same way build and then connect to itunes connect and follow from there. In this case the existing NSUserDefaults is untouched right ? As in the simulator it is untouched when i make changes to the code (unless I reset contents and settings).

    Also, Is it a good iPhone programming practice to also save the NSUserDefaults to a plist ??

    I don't see any reason to do that. if your settings in NSUserDefaults are getting deleted, so will anything you could save to a plist. iOS apps can only save to files in their sandbox, and if the user deletes your app, all your sandboxed files get deleted.
    Regards,
    Duncan C
    WareTo

    widehead.gif
    Animated GIF created with Face Dancer, available for free in the app store.

    I'm available for one-on-one help at CodeMentor
  • kevincobain2000kevincobain2000 Posts: 40New Users
    @Duncan Thanks, I also imagined so & just needed to confirm.
    Mountain Lion | xcode 4.5
    http://www.jaist.ac.jp/~s1010205
Sign In or Register to comment.