Detailed Explanation of IOS Development Object Empty Judgment (nil null)

  • 2021-11-02 03:00:35
  • OfStack

Detailed Explanation of IOS Development Object Empty Judgment (nil, null)

Foreword:

In development, you will encounter many empty situations. Sometimes you get the object (null), and sometimes you get it < null > In the case, we need to judge whether it is empty and carry out return;;


  id result;
//  For ( null ) This situation 
  if(result == nil) return;
//  Aim at <null> The situation of 
  if([result isEqual:[NSNull null]]) return;

The former judgment, we use more frequently, but the latter, with less, 1 assign values to other null values except nil;

Null value judgment of basic data type

Null value judgment for data similar to NSString type


NSString *string;
1 , string == nil;
2 , [string isEqualToString:@""];

Null value judgment for data similar to NSNumber type


NSNumber *number;
1 , number == nil;
2 , [number isEqualToNumber:@0]

Null value judgment for data similar to NSArray type


NSArray *array;
1 , array == nil;
2 , array.count = 0;

Null value judgment for data similar to NSDictionary type


NSDictionary *dictionary;
1 , [dictionary isEqual:[NSNull null]];
2 , dictionary.count = 0;

Null value judgment for data of object type

Can be used! (Not) to judge


if (! class )  return;

Thank you for reading, hope to help everyone, thank you for your support to this site!


Related articles: