views:

98

answers:

3

I want to check to see if an array has "-" to activate a shipping method. I put "-" in since the array value will aways =2 and I need to IF ELSE by the contents. If the user doesn't not enter an address in the contents of the array looks like this:

Root   Array   (2items)  
Item 1 String   -  
Item 2 String   -

Here is the code for returning the array.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullFileName = [NSString stringWithFormat:@"%@/arraySaveFile", documentsDirectory];
NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:fullFileName];

I want to write something like:

if ([fullFileName isEqualToString:@"-","-"]) 
{
[nnNEP EnableShipping];
}
else {
[nnNEP DisableShipping];
}

I just can't find the right or description on how to adjust it so that it compares both of the "-"'s in the array.

A: 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullFileName = [NSString stringWithFormat:@"%@/arraySaveFile", documentsDirectory];
NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:fullFileName];

if ([fullFileName isEqualToString:@""]) {
    [nnNEP EnableShipping];
}
else {
    [nnNEP DisableShipping];
}

if ([array count] == 0) {
    [nnNEP EnableShipping];
}
else {
    [nnNEP DisableShipping];
}
David Kanarek
Thanks for your time.. I posted a better question and it got answered.
Michael Robinson
+1  A: 

Try:

if ([fullFileName isEuqalToString:@""])
{
    [nnNEP EnableShipping];
}
else
{
    [nnNEP DisableShipping];
}

Or:

if ([array count] == 0)
 {
    [nnNEP EnableShipping];
}
else
{
    [nnNEP DisableShipping];
}
Kevin Sylvestre
Thanks, I edited my question to only compare string values of both items in array,can you check it out?
Michael Robinson
Thanks for your time.. I posted a better question and it got answered.
Michael Robinson
A: 

Since you did a stringWithFormat into fullFileName, it's never empty or nil so it's pointless to check that.

So then you want the array contents check - since you can send messages to nil it doesn't matter if the array is empty or nil, this will work the same way.

if ( array.count == 0 ) 
    [nnNEP EnableShipping];
else 
    [nnNEP DisableShipping];
Kendall Helmstetter Gelner
Thanks, I edited my question because the value would have always been 2 items.
Michael Robinson
Thanks for your time.. I posted a better question and it got answered.
Michael Robinson