Reputation: 1439
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.
Upvotes: 0
Views: 243
Reputation: 75058
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];
Upvotes: 0
Reputation: 38012
Try:
if ([fullFileName isEuqalToString:@""])
{
[nnNEP EnableShipping];
}
else
{
[nnNEP DisableShipping];
}
Or:
if ([array count] == 0)
{
[nnNEP EnableShipping];
}
else
{
[nnNEP DisableShipping];
}
Upvotes: 1
Reputation: 12613
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];
}
Upvotes: 0