Dancer
Dancer

Reputation: 17681

IOS String length comparison issue

I'm struggling with an if Comparison - I basically want to make two comparisons - both of which need to pass - Firstly a basic if a string variable is equal to 'rec' and secondly if a strings character limit is not equal to zero.

I've tried various combinations - but this is where i'm at at the mo..

 ArticleObject *A = [self.articleArray objectAtIndex:indexPath.section];
 NSInteger imglength = [A.arImage length];

 if([A.arRec isEqual: @"rec"] ) && (imglength !=Nil){
     return 195;
 }
 else return 50;

I get an expected identifier error on the (imglength comparison - as in this screen shot enter image description here

Can anyone shed any light for me please?

Upvotes: 0

Views: 93

Answers (2)

meda
meda

Reputation: 45500

Your parentheses are messed up:

if([A.arec isEqualToString:@"rec"] && (imglengyb !=Nil))
                                                      ^--------------//here

Maybe a better way would be:

if([A.arec isEqualToString:@"rec"] && [[A.arImage length] != 0])

Upvotes: 0

rmaddy
rmaddy

Reputation: 318934

There are several things you should change:

ArticleObject *A = self.articleArray[indexPath.section];
NSInteger imglength = [A.arImage length];

if (imglength && [A.arRec isEqualToString:@"rec"]) {
     return 195;
} else {
     return 50;
}

Don't use Nil (or nil) with primitive types.

Upvotes: 2

Related Questions