Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

object return empty description in iOS

Tags:

ios

nsstring

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

like image 546
user1960169 Avatar asked Jan 07 '23 11:01

user1960169


1 Answers

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
{
}
like image 149
Midhun MP Avatar answered Jan 10 '23 00:01

Midhun MP