0

I have this simple code to save and restore boolean from NSUserDefaults. At the end when I do

po [defaults boolForKey:@"dummy"]

in the debugger I see nil.

What is going on here ?

// Store the data
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

[defaults setBool:(BOOL)boolValue forKey:@"dummy"];

[defaults synchronize];

BOOL ans = [defaults boolForKey:@"dummy"];

Where am I wrong ?

Thanks!

UPDATED: Thanks! Now clear

Bill Lumbert
  • 3,943
  • 2
  • 18
  • 29

1 Answers1

4

If you do

p [defaults boolForKey:@"dummy"]

(which is a proper debugging command for printing primitive types) instead of

po [defaults boolForKey:@"dummy"]

you will see NO

po means print object and is suitable for descendants of NSObject

p is just print and is suitable for primitives like BOOL or int

Andrey Chernukha
  • 21,004
  • 16
  • 95
  • 160