hello I am doing something like this.
NSString * fblink=[dm.commonDataArray valueForKey:@"fb_link"];
if(![fblink isEqual:[NSNull null]]||![fblink isEqualToString:@""]||![fblink length]<=0)
{
[fb_button setImage:[UIImage imageNamed:@"ico_user_fb"] forState:UIControlStateNormal];
[fb_button addTarget:self
action:@selector(buttonFBTouch:)
forControlEvents:UIControlEventTouchUpInside];
}else{
[fb_button setImage:[UIImage imageNamed:@"ico_fb_red_gray"] forState:UIControlStateNormal];
}
when I type fblink
in my log it says (lldb) po fblink
<object returned empty description>
But still my if condition become true and go inside ratherthan going to else part.
How can I overcome this problem?I dont want to execute my if condition true part if its return empty description. How can I checked this condition? Please help me Thanks
The problem is with your if condition. fblink
is nil
, you are checking nil is equal to [NSNull null]
so this case fails and you invert the result so it becomes true and goes inside of this if case.
If we expand your if case it becomes:
if(![nil isEqual:[NSNull null]]||![nil isEqualToString:@""]||![nil length]<=0)
{
}
Which becomes
if(!false||!false||!true) // which evaluates to true, you are using ||, so if any one condition is true, it will go inside of the if case
{
}
You need to change that if case to:
if([fblink isKindOfClass:[NSString class]] && ![fblink length]<=0)
{
}
else
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With