How To Detect If Array Displays These Results
How would I detect if an array displays the following in an if statement? (I tried NULL and it didn't work)...
When I NSLog the description of t开发者_StackOverflowhe array, this is what returns:
NSLog(@"%@", [manager purDesc]description]);
2011-08-30 13:43:20.227 PROJECT[2921:f503] manager purDesc Dump:(
{
amt = "\n ";
desc = "\n ";
}
)
I need to say "If [manager purDesc]
looks like that, display a UIAlertView
".
Sorry everyone, I feel like I'm having trouble getting my point across this morning. If you don't understand, please comment with your question and I'll try to explain better.
Actually, your structure seems to be a dictionary inside an array. Not sure how that all stacks up. To see if all items in a dictionary are only whitespace.
BOOL empty = YES;
NSCharacterSet* wp = [NSCharacterSet whitespaceAndNewlineCharacterSet];
for(NSString* key in dict)
{
NSString* val = [dict objectForKey: key];
// trim white space and check length
if([[val stringByTrimmingCharactersInSet: wp]length])
{
empty = NO;
break;
}
}
the array version is left as an exercise to the reader. :-)
If those fields are NSString
, you might want to check out stringByTrimmingCharactersInSet:
.
NSString* trimmedAmount = [amt stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
You can remove whitespace and returns by using the NSString method stringByTrimmingCharactersInSet: along with the static set whitespaceAndNewlineCharacterSet.
However, based on the output of [purDesc description], it looks like you may have an NSDictionary, not an array.
Why don't you check the actual elements of the array? somehting like
[manager objecAtIndex:0] = nil
精彩评论