Question: I save a bool value in NSUserDefaults like this:

```
[[NSUserDefaults standardUserDefaults]setBool:NO forKey:@"password"];

```

And then I synchronize defaults like this:

```
[[NSUserDefaults standardUserDefaults]synchronize];

```

But when my app enters background and then enters foreground my bool changes value to `YES`

Why does that happen ? I set my bool to `YES` only in one place in program, which is not managing when my app leaves/enters foreground.

Thanks!

Answer: 
Your retrieval code should look something like this.

```
if(![[NSUserDefaults standardUserDefaults] boolForKey:@"password"]) {
    //False
} else {
    //True
}

```
Make sure you have the right key string (`@"password"` in your case) when you retrieve the boolean value. It is case sensitive.

```
[[NSUserDefaults standardUserDefaults] boolForKey:@"password"];

```

Do a text search in your whole project for this key and you will find the offending code.