Зависит, если вы ищете какие-либо пробелы или просто пробелы. Для пробелов вы можете использовать:
if( [string length] == 0 ||
!NSEqualRanges( [string rangeofString:@" "],
NSMakeRange(NSNotFound, 0) ) )
{
// either the string is empty or we found a space
} else {
// we didn't find a space and the string is at least of length 1
}
Если есть пробел, используйте набор символов пробела:
if( [string length] == 0 ||
!NSEqualRanges( [string rangeOfCharacterFromSet:
[NSCharacterSet whitespaceCharacterSet]],
NSMakeRange(NSNotFound, 0) ) )
{
// either the string is empty or we found a space
} else {
// we didn't find a space and the string is at least of length 1
}
Замените whitespaceCharacterSet
на whitespaceAndNewlineCharacterSet
, если хотите.