NSZombieEnabled won't turn off - objective-c

I have NSZombieEnabled to NO in my arguments.
I am checking to see if it is enabled:
if(getenv("NSZombieEnabled") || getenv("NSAutoreleaseFreedObjectCheckEnabled"))
{
NSLog(#"NSZombieEnabled/NSAutoreleaseFreedObjectCheckEnabled enabled!");
}
My debugger says it is still enabled. Why?

try to uncheck it. If it has no checkmark in front it shouldn't be passed to the application.
It should be off when you set the value to NO, but getenv("NSZombieEnabled") will return "NO". Which is not a boolean NO but a cstring "NO". So the if condition will be true anyway.

I know this question is old, but for people’s reference, you can use this technique for many debug flags:
extern BOOL NSZombieEnabled;
if (NSZombieEnabled)
...
If it links, it will work.

Here's a suggestion which checks for both the existence of the env variable and the correct value.
char* szZombie = getenv("NSZombieEnabled");
if (szZombie && 0 == strcasecmp(szZombie, "YES"))
{
NSLog(#"NSZombieEnabled enabled!");
}

Related

In Swift, can you pass nil as an input to a function?

I'm reading many articles about how you shouldn't check an object for nil. It's a objC paradigm and it's a bad design and w/ swift it's been eliminated. So my question is, per example below, can you pass thru "group" as nil value? does the nil-checking mechanism happen when the function is called, hence removing the need to implement if(group==nil){..} ?
func deleteMembershipForGroup(group:GroupData){
}
You need to use an optional:
func deleteMembershipForGroup(group:GroupData?){
if let groupReal = group {
// not nil
}
}
Yes! Thomas Kilian is right and it works for me! You will then be able to pass a nil parameter. You will also notice that using optional variable, it will also removed the warning saying the variable "group" will always be true.
func deleteMembershipForGroup(group:GroupData?){
if let groupReal = group { <--- Warning gone!
// not nil
}
}

Assert with string argument not working as expected

EDIT: The issue was with the assert as people pointed out below. Thanks for the help!
I have a enum set that i'm trying equate, but for some reason its not working.
Its declared like so:
typedef NS_ENUM(NSUInteger, ExUnitTypes) {
kuNilWorkUnit,
kuDistanceInMeters,
//end
kuUndefined
};
And i'm using it here:
+(NSString*) ExUnitDescription: (ExUnitTypes) exUnit
{
if (exUnit == kuNilWorkUnit)
{
assert("error with units");
}
///.... more stuff
}
Xcode isnt triggering my assert. EDIT: the assert is just for testing. i've used NSLog as well. The conditional isn't evaluating to true even though the value is clearly kuNilWorkUnit.
Does anyone have any suggestions or ideas of what i'm doing wrong?
You want to do this:
+(NSString*) ExUnitDescription: (ExUnitTypes) exUnit
{
assert(exUnit != kuNilWorkUnit);
///.... more stuff
}
This is because, assert only stops execution if the expression you pass to it is false. Since a string literal is always non-zero, it will never stop execution.
Now, since you are using Objective C and it also looks like you want to have a message associated with your assert, NSAssert would be preferable.
+(NSString*) ExUnitDescription: (ExUnitTypes) exUnit
{
NSAssert(exUnit != kuNilWorkUnit, #"error with units");
///.... more stuff
}

Yii trace - proper usage

Unit testing and xdebug usage aside, I wish to have a way to throw some browser message is a value is not expected to be present.
Let's say: $className = 45;
If we have:
public function setMainClass($className) {
if (is_string($className)) {
$this->_mainClass = $className;
} else {
echo Yii::trace(CVarDumper::dumpAsString($className),'vardump');
}
}
We will get this output to the browser on development stage.
It's great.
I'm not sure however, if this is a proper way of use Yii::trace of if I'm miss using it.
Please advice.
It is not necessary to echo the call Yii::trace() (it returns void so the echo does nothing). The other recommendation is that you might consider changing category to resemble a path alias as discussed in the documentation. For example-
} else {
Yii::trace(CVarDumper::dumpAsString($className), 'application.models.MyGreatModel');
}

Clang static analyzer warning "Null pointer argument in call to CFRelease"

In Xcode 4.6, the clang static analyzer warns me about a "Null pointer argument in call to CFRelease".
Here's a screenshot of the analyzer warning:
And here's the code in case you want to copy & paste it:
- (void)test
{
CFUUIDRef aUUID = CFUUIDCreate(kCFAllocatorDefault);
[self setUUID:aUUID];
CFRelease(aUUID);
}
- (void)setUUID:(CFUUIDRef)uuid
{
_uuid = uuid ? CFRetain(uuid) : CFUUIDCreate(kCFAllocatorDefault);
}
I don't understand why it is warning me. aUUID can never be a null pointer, can it? I've learnt to rather mistrust myself than the tools I'm using, so I'm asking here. I would be very glad if someone explained to me what I'm missing.
Anything returning an allocated value could, in theory, return NULL.
The analyzer follows multiple possible paths of execution. While following the "aUUID is NULL" scenario, it eventually ends up at the CFRelease of the NULL object.
It's not that setUUID is the cause, that's just the path along which the issue was spotted, so that's the path that's illustrated.

Velocity: Is a any way to check if variable is defined

I want to include one template nested into others cont1, cont2, cont3.
And nested template should be hide one specific control for cont1 only.
Before inclusion into cont1 I would like to assign value to some flag variable $hideMyControl.
And inside nested template I would like to check if $hideMyControl is assigned value.
How to perform such check?
#if($hideMyControl)
// your code
#end
If $hideMyControl is defined, your code will execute
You can do this using
#if($!{$articleLeader})
// Perform your operation or the template part you want to show.
#end
For more info, see the 'formal reference' section of the Apache Velocity Reference Manual.
#if($!{hideMyControl} != "")
## do something if $hideMyControl is defined
#end
This works for me in AWS API Gateway Body Mapping Templates. Please refer to Quiet Reference Notation in Velocity User Guide for more information.
I was using
#if ($hideMyControl)
//do something
#end
since a few months ago,
however today its not working anymore.
I came here to find help, and noticed a new way of writing it :
#if($!{$hideMyControl})
// do something
#end
this code works!
According to the docs for Strict Reference Mode it is possible to several constructions to check if variable is defined.
#if ($foo)#end ## False
#if ( ! $foo)#end ## True
#if ($foo && $foo.bar)#end ## False and $foo.bar will not be evaluated
#if ($foo && $foo == "bar")#end ## False and $foo == "bar" wil not be evaluated
#if ($foo1 || $foo2)#end ## False $foo1 and $foo2 are not defined
So this code works in my case.
#if( !$value )
// Perform your operation or the template part you want to show.
#end
To check if $hideMyControl is in Velocity context and IS NOT boolean 'true' value (or 'false' as well):
#if ($hideMyControl && $hideMyControl != true)
##do stuff
#end
Sure, if you really use your $hideMyControl variable as boolean type, you don't need second part of condition.