IOS-based method for determining whether a string is null
-(BOOL) isBlankString :( NSString *) string {
If (string = nil | string = NULL ){
Return YES;
}
If ([string isKindOfClass: [NSNull class]) {
Return YES;
}
If ([[string stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet] length] = 0 ){
Return YES;
}
Return NO;
}
NSNull is a special class, which is the same as nil and also represents a null value. But there is a difference between the two. NSNull does not accept NSArray's methods. It has only one class method:
+(NSNull *)null;
Therefore, sending NSArray-specific method or attribute access will cause program crash. A major part of the null value judgment is to ensure the stability of the program when the background interface data returns some abnormal data.
For example, in some cases, the background may return a null value for a field for various reasons. In this case, we get an object such as [NSNull null]. For example, the backend may have a value for a certain data, but 0 is returned. In this case, an empty group is returned. what we get is @ [], an empty group.
Therefore, to determine whether the array is null, You need to determine all situations. There are many writing methods, such as writing:
if (array != nil && ![array isKindOfClass:[NSNull class]] && array.count != 0)