Questions tagged [nsuserdefaults]

NSUserDefaults is the Objective-C API for storing and retrieving user preferences in Apple's Foundation framework for Cocoa and Cocoa Touch. It is available in OS X v10.0 and later and Available in iOS 2.0 and later which is inherited from NSObject root class

NSUserDefaults provides a cross-process hierarchical key-value store for use in Cocoa and Cocoa Touch applications. It is equivalent to and compatible with the CFPreferences C API in CoreFoundation.

This class provides a programmatic interface for interacting with the defaults system.At runtime, NSUserDefaults object is used to read the defaults that an application uses from a user’s defaults database. NSUserDefaults caches the information to avoid having to open the user’s defaults database each time you need a default value . The questions related to this can be tagged with

Source:

Question related to this are:

  1. iOS: How to store username/password within an app?

  2. Clearing NSUserDefaults

  3. How to store custom objects in NSUserDefaults

  4. Easy way to see saved NSUserDefaults?

3775 questions
1
vote
1 answer

If statement in NSUserDefault when loading a string

I have the following code for saving a value and an string. I want to use If statement to check my value. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:@"Baseball bat" forKey:@"Weaponsname"]; …
Clarence
  • 1,951
  • 2
  • 34
  • 49
1
vote
2 answers

Problems in getting an array from NSUserDefaults

I am making a game using cocos2d-iphone and would like to make a screen with best previous scores. I have two scenes. In the MainScene I made a global variable for storing a score, that is obviously changing during the game; one mutable array and…
user3475724
1
vote
1 answer

Sharing data between app extension and conainer app

I'm trying to share data between an app extension and my container app. I setup an app group in the container app and referenced it my app extension. When my app extension is accessed, I save an object to NSUserDefaults //in the app…
Avba
  • 14,822
  • 20
  • 92
  • 192
1
vote
1 answer

Cant set Array in NSUserDefaults

var arr = defaults.arrayForKey("kWeeks") as [WeekReport]? if arr? { var arr2 = arr! arr2.append(report) defaults.setObject(arr2, forKey: "kWeeks") // Crash defaults.synchronize() } I try to set arr2 which will be the add…
Arbitur
  • 38,684
  • 22
  • 91
  • 128
1
vote
2 answers

How to check existence of reference to an NSManagedObject?

I successfully stored and retrieved a reference to an NSManagedObject using the example found in this site http://cocoawithlove.com/2008/08/safely-fetching-nsmanagedobject-by-uri.html The problem is, the app crash whene triying to retrieve an…
Davide
  • 764
  • 1
  • 6
  • 18
1
vote
0 answers

NSUserDefaults standardUserDefaults and editing value with "defaults write" in console

I'm using NSUserDefaults (on Mac OS X 10.9) to store some string value (if there is none already): NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults]; _kUpdatesSharedLocationPath = [standardUserDefaults…
Piotr Byzia
  • 3,363
  • 7
  • 42
  • 62
1
vote
2 answers

Delete NSUserDefault key value when app quits

I have saved an NSString in my NSUserDefault with key @"userKey". I want to be able to reset this value to @"" when the app is totally shut down but not when it enters the background. I have tried: [[NSUserDefaults standardUserDefaults]…
user1114881
  • 731
  • 1
  • 12
  • 25
1
vote
2 answers

EXC_BREAKPOINT on launch after using NSUserDefaults on iOS 8 Swift on iPhone 5s, not simulator

Just after implementing a method for saving a users email and password from login into NSUserDefaults. My app crashes when running on iPhone 5s, but not in simulator (works as supposed). Error message is: dyld: Symbol not found:…
Simon Guldstrand
  • 488
  • 1
  • 5
  • 24
1
vote
3 answers

EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) in Swift

I am trying store & get data in NSUserDefaults, when application launch at first time value for "token" in NSUserDefaults is nil. On application launch I am trying to get it from standardUserDefaults(), but it fails & give an error…
OnkarK
  • 3,745
  • 2
  • 26
  • 33
1
vote
2 answers

How do I save and load a picture to view on another view controller using nsuserdefaults and .hidden

I have to squares on the first view controller its hidden at anytime and when the app launches you have two button white and black. when the user presses on either button and press on back to view 1 it shows either the white square and black square…
1
vote
2 answers

how to run a code exactly once for all of its life for each user in objective-c

is there a way to run a code only once?Not for each usage.When the user download the app and runs it, the code will run only once and not anymore. i tried to create a integer with initial 0 and save it to nsuerdefaults. and made this special code in…
judge
  • 195
  • 1
  • 4
  • 14
1
vote
4 answers

NSUserDefaults can't update a nsmutable array

I saved a nsmutableArray inside a NSUserDefaults. In the following case, it seems that all the elements from the array are equal to 0, even though in this case position 1 and position 5 should have 1 instead of 0 as a value. I know that…
just ME
  • 1,817
  • 6
  • 32
  • 53
1
vote
2 answers

Best practice for multiple users: Core Data or NSUserDefaults

I'm developing an app that can have multiple users. I mean, when a user downloads the app, he'll have 1 user ( default ), but he can add more users for his parents/sons/wife/etc. And each user will have his own data. So my question is: What is the…
Bader Al-Rasheed
  • 458
  • 1
  • 7
  • 13
1
vote
0 answers

present settings child view modally

If presenting child settings view in settings bundle modally possible, how it can be achieved? I have looked at Apple Documentation "Preferences and Settings Programming Guide", but found only a description of how to push it onto navigation…
Alua K
  • 398
  • 1
  • 3
  • 18
1
vote
0 answers

Why do some keys in NSUserDefaults have quote marks while others do not?

When I log my app’s NSUserDefaults by passing the results of this code to NSLog: [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]] …I get results such as seen in this excerpt. WebKitXSSAuditorEnabled = 1; WebKitZoomsTextOnly =…
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
1 2 3
99
100