Smitha
Smitha

Reputation: 6134

Comparison doesn't yield result in iOS

I am trying to compare two items' id and it's never being true though its actually meets te=he expected condition.

-(int) calculateScore : (int) itemId{

   NSLog(@"Item id count..:: %d", vmScore.itemIdArray.count);
   for(int i=0; i<vmScore.itemIdArray.count; i++){

       if(itemId == vmScore.itemIdArray[i]){
          score += 10;
      }
    }

   return score;
}

itemIdArray is an array of integer and itemId is fetched from - SafetyDeviceIdArray[i], again a NSMutable array property.

Upvotes: 0

Views: 43

Answers (2)

Premal Khetani
Premal Khetani

Reputation: 3195

Use Following code to fulfill your requirement.

-(int) calculateScore : (int) itemId{

   NSLog(@"Item id count..:: %d", vmScore.itemIdArray.count);
   for(int i=0; i<vmScore.itemIdArray.count; i++){

       if(itemId == [vmScore.itemIdArray[i] intValue]){
         // Your code goes here 
         score += 10;
      }
    }

   return score;
}

Upvotes: 3

Ganesh Kamath
Ganesh Kamath

Reputation: 1181

Use

if (itemId == [vmScore.itemIdArray[i] intValue]) {
 score += 10;
}

instead of

if (itemId == vmScore.itemIdArray[i]) {
 score += 10;
}

Upvotes: 1

Related Questions