Solution to IOS development empty strings
Example code:
-(Boolean) isEmptyOrNull:(NSString *) str { if (!str) { // null object return true; }else if(str == Null){ return true; }else if([str isKindOfClass:[NSNull class]]){ return true; }else { NSString *trimedString = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; if ([trimedString length] == 0) { // empty string return true; } else { // is neither empty nor null return false; } } }
str may be nil, NSNull class, or length may be 0.
If you use the statement in the last else directly, if it is NSNull, an exception such as NSNull length is reported.
The above is the solution to IOS empty characters. If you have any questions, please leave a message or go to the community of this site to communicate and discuss. Thank you for reading. I hope it can help you. Thank you for your support for this site!