Siva Sankar
Siva Sankar

Reputation: 543

How to write the condition for BOOL values

this is my response

1.{

    image = nbYijSxVXDOFGWFk8BhZUpU
    "is_food_in_time_product" = 1;
    "list_price" = "2.8";
    name = Export;

}
2.
{

    image = 0;
    "is_food_in_time_product" = 1;
    "list_price" = 1;
    name = "K\U00e4se";

}

NSString *abc5 = [abc4 valueForKey:@"image"];
NSLog(@"%@",abc5);

Here first response image coming data, second response image no data.Then How to write the if condition.

Upvotes: 1

Views: 144

Answers (4)

Himanth
Himanth

Reputation: 2446

Based on url you have to do like this:

    NSDictionary *responseDataDictionary = responseObject;
    //here responce object is your total data which is coming from server
    NSArray *array = [[responseDataDictionary valueForKey:@"result"] valueForKey:@"products"];
          for (NSDictionary *dict in array)
          {
               NSString *str = [dict valueForKey:@"image"];
               if([str isKindOfClass:[NSString class]])
               {
                    NSLog(@"YES");
                    //here you have to add your image as usual to another mutable array
               }else{
                    NSLog(@"NO");
                    // bool value happens means this will execute
                    // Here you have to add custom image ie.placeholder image
               }

          }
    }

that's it cheers

Upvotes: 1

Pooja Srivastava
Pooja Srivastava

Reputation: 721

NSNumber * isSuccessNumber = (NSNumber *)[abc4 valueForKey:@"image"];
if([isSuccessNumber boolValue] == YES)
{
  NSLog(@"Image is available");
} else {
  NSLog(@"Image is not available");
}

your response is like this

1st condition:

 NSDictionary *r1 = @{@"bool" : @(1)};

NSNumber * isSuccessNumber = (NSNumber *)[r1 valueForKey:@"bool"];
if([isSuccessNumber boolValue] == YES)
{
    NSLog(@"Image is available");
} else {
    NSLog(@"Image is not available");
}

Output1

Image is available

2nd condition:

NSDictionary *r1 = @{@"bool" : @(0)};

NSNumber * isSuccessNumber = (NSNumber *)[r1 valueForKey:@"bool"];
if([isSuccessNumber boolValue] == YES)
{
    NSLog(@"Image is available");
} else {
    NSLog(@"Image is not available");
}

Output2

Image is not available

Upvotes: 1

Shivbaba's son
Shivbaba's son

Reputation: 1369

It is a Dictionary within Array that you stored.

//Here index is an integer value, showing the index of an array responseArray.
if[responseArray[index][@"image"] intValue]!=0){

    //Load image
}else{
    //Do not load image
}

Upvotes: 0

user3182143
user3182143

Reputation: 9589

You need to check whether image(data) is nil or not

First you can directly check

if (image != nil)
{
  ....
}
else{
  ...
}

Then after converting image(data) into string(abc5)

if(abc5 length] == 0)
{
   ....
}
else
{
  ....
}

Upvotes: 0

Related Questions