Odd Behaviour of BOOL in iOS7

I might be going mad here, but previously when using a BOOL I would do something like this :

BOOL myBool

if (myBool) {
  NSLog@"My Bool is YES";

I.e I would assume that if myBool is equivalent to saying if myBool is YES.

Under iOS7 though I am seeing the log statement trigger even when the value of myBool is never explictily set. If it is set to NO or YES the code behaves as expected.

Has something changed here under iOS7 ?


Just to add that this moment of madness was caused but the fact that I had been elsewhere initialising BOOLs from NSUserDefaults boolForKey method, which will return NO if no value is found for that key.


If myBool is never explicitely set and it's a local variable, then its value is UNDEFINED. Therefore, it can evaluate to either YES or NO.

Aren't you getting some compiler warnings?

BOOL myBool is not initialised to any value in your code so it may have any random values either YES or NO..

Initialize your myBool to some value first..

Need Your Help

which multi-touch hardware devices are programmable via Adobe AIR 2?

flex3 air flex4

Thank you for your interesting in my question. You can help me out from this little problem.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.