首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何编写BOOL值的条件

如何编写BOOL值的条件
EN

Stack Overflow用户
提问于 2016-09-29 10:55:16
回答 4查看 136关注 0票数 1

这是我的回应

代码语言:javascript
复制
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);

这里第一响应图像来的数据,第二响应图像没有data.Then如何写的中频条件。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2016-09-29 12:52:05

基于url,您必须这样做:

代码语言:javascript
复制
    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
               }

          }
    }

就这样干杯

票数 1
EN

Stack Overflow用户

发布于 2016-09-29 11:09:06

代码语言:javascript
复制
NSNumber * isSuccessNumber = (NSNumber *)[abc4 valueForKey:@"image"];
if([isSuccessNumber boolValue] == YES)
{
  NSLog(@"Image is available");
} else {
  NSLog(@"Image is not available");
}

你的反应是这样的

第一条件:

代码语言:javascript
复制
 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

图像可用

第二条件:

代码语言:javascript
复制
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

图像不可用

票数 1
EN

Stack Overflow用户

发布于 2016-09-29 11:08:29

您存储的是DictionaryArray中。

代码语言:javascript
复制
//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
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39768348

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档