Baub
Baub

Reputation: 5044

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 the 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.

Upvotes: 0

Views: 61

Answers (4)

Nungster
Nungster

Reputation: 726

Why don't you check the actual elements of the array? somehting like

[manager objecAtIndex:0] = nil

Upvotes: 0

user846945
user846945

Reputation:

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. :-)

Upvotes: 2

picciano
picciano

Reputation: 22701

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.

Upvotes: 0

zpasternack
zpasternack

Reputation: 17898

If those fields are NSString, you might want to check out stringByTrimmingCharactersInSet:.

NSString* trimmedAmount = [amt stringByTrimmingCharactersInSet:
  [NSCharacterSet whitespaceAndNewlineCharacterSet]];

Upvotes: 0

Related Questions