NSMutableArray indexOfObject returning an extremely large number

前端 未结 2 1494
一生所求
一生所求 2021-01-21 12:19

I have an NSMutableArray returning an extremely large index?

po [masterArray count] < returns \"2\"

NSUInteger theIndex = [masterArray indexOfObject:valida         


        
相关标签:
2条回答
  • 2021-01-21 12:49

    That's the value for NSNotFound. This means the object you are looking for isn't in the array.

    0 讨论(0)
  • 2021-01-21 12:58

    Try it like this. validateEnrollmentStatus is not present in masterArray. So you can probably add a check for that before you try to get the indexOfObject.

        NSUInteger theIndex = 0;
    
        if ([masterArray containsObject:validateEnrollmentStatus]) {
            theIndex = [masterArray indexOfObject:validateEnrollmentStatus];
        } else {
            NSLog(@"%@ is not present in masterArray", validateEnrollmentStatus);
        }
    
    0 讨论(0)
提交回复
热议问题