-(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, like Nil, also represents a null value, but there is a difference between them, nsnull do not receive nsarray of those methods, it has only one class method:
+(NSNull *)null;
Therefore, sending nsarray-specific methods or property access will cause the program to crash. A big part of our short value judgment is that the program guarantees stability when the backend interface data returns some of the exception data.
For example: In some cases, the background may return a null value for a field for a variety of reasons, when we get to [NSNull null] Such an object, for example, the background may be a value for a certain data, but took 0, then returned is an empty group, we take the @[] , an empty group.
Therefore, it is necessary to judge whether the array is empty. There are many kinds of writing, such as you can write:
if (array != nil && ![array isKindOfClass:[NSNull class]] && array.count != 0)
How iOS determines if a string is a null character