-1

view and viewcontroller are separate. I am already tried NSUserDefaults it's not working.

[[NSUserDefaults standardUserDefaults] setValue:BOOLCondition forKey:@"YES"];
[[NSUserDefaults standardUserDefaults] synchronize];

it's say impact conversion of bool to id is disallowed with arc

how to pass that bool value

***** view to viewcontroller not viewcontroller to viewcontroller

Popeye
  • 11,839
  • 9
  • 58
  • 91
Mathi Arasan
  • 869
  • 2
  • 10
  • 32
  • Reading the title, it seems to me you want to pass a value from a view controller to a view. In the question you say “view to viewcontroller”. Which is it? – Raphael Schweikert Mar 16 '15 at 10:40
  • Have you tried googling the error before asking a question? Also, you're question/code has nothing to do with view/view controllers. – Lord Zsolt Mar 16 '15 at 10:42

2 Answers2

6

Use the below code to store BOOL value in NSUserDefaults

BOOL BOOLCondition = YES; or BOOL BOOLCondition = NO;

[[NSUserDefaults standardUserDefaults] setBool:BOOLCondition forKey:@"YES"];
[[NSUserDefaults standardUserDefaults] synchronize];
Kirit Modi
  • 23,155
  • 15
  • 89
  • 112
  • 1
    That key name is suspicious. Looks like the key and value are reversed (i.e. `BOOLCondition` is actually the key)... – trojanfoe Mar 16 '15 at 10:52
4

I always do this to store a BOOL value, because I prefer better to work objects directly:

BOOL _myBool = TRUE; // or FALSE...
[[NSUserDefaults standardUserDefaults] setValue:@(_myBool) forKey:@"boolValue"];
[[NSUserDefaults standardUserDefaults] synchronize];

and restoring back the stored value:

BOOL _boolValue = [[[NSUserDefaults standardUserDefaults] valueForKey:@"boolValue"] boolValue]; // will be FALSE if the value is `nil` for the key
holex
  • 23,961
  • 7
  • 62
  • 76
  • 1
    `BOOL` values in Objective-C are `YES` and `NO`, by convention. – trojanfoe Mar 16 '15 at 10:52
  • actually I could also use the number `0` for _false_ or number `1` for _true_; it would be the same outcome – as these are the default values for those in Obj-C; nevertheless I could also use any non-zero value for _true_, it'd work as well correctly. :) – holex Mar 16 '15 at 11:02
  • But the convention is to use `YES` and `NO`. – trojanfoe Mar 16 '15 at 11:05
  • yes, they would work as well; and I have not denied that convention at all! :) as we both know, in runtime they are pretty much `0` and non-zero (mostly `1`) values which are stored on an `unsigned char` – and the `TRUE` and `FALSE` value are defined as same as the `YES` or `NO`, luckily there won't be any interference exchanging them. ;) – holex Mar 16 '15 at 11:32
  • Is there a difference in the object returned from `@(YES)` and `@(TRUE)`? – trojanfoe Mar 16 '15 at 11:34
  • they both look identical to `@(1)`. – holex Mar 16 '15 at 11:36
  • OK, doesn't matter then. – trojanfoe Mar 16 '15 at 11:37