I want to have a static boolean like in Java. This boolean only created once for the entire class, no matter how many instance it has.
I read some posts here. Some of them are suggesting that in .m file
, init this variable like
static BOOL myBool = NO;
and then have a getter and a setter function. But I was told that this is not safe and clean in Objective C. A safer and cleaner way to do this is init static variable in function. But if I init it in a function, like
+(Bool)getMyBool {
static BOOL myBool = NO;
return myBool;
}
In this way myBool will always NO. What if I want to set this boolean afterwards? If I call static BOOL myBool
again, would it give me the same boolean?