Why is '[self.pickerSubArray indexOfObject: self.txtSubCategory.text]' return '2147483647'?

why '[self.pickerSubArray indexOfObject: self.txtSubCategory.text]' return '2147483647'; while the same string value argument '[self.pickerSubArray indexOfObject: @ "Mark"]' raises 4 if necessary?

+3
source share
3 answers

Apple docs for NSArray (which I assume your object is based on name), say that indexOfObject:returns NSNotFoundif the object does not match any of the array. NSNotFounditself is defined as NSIntegerMax, which, as others have pointed out, is the value that you return.

indexOfObject:uses isEqual:to compare elements, so theoretically, if the text is the same, it should work. Perhaps the text is different in that you did not notice, for example, a case (“Mark” or “mark”) or an additional addition (“Mark” and “Mark”).

+13
source

indexOfObject: NSNotFound, . NSNotFound NSIntegerMax, 2147483647.

? , indexOfObject: , . .

NSString *mark1 = [NSString stringWithString:@"Mark"];
NSString *mark2 = [NSString stringWithString:@"Mark"];

mark1 mark2, .

NSString *mark1 = [NSString stringWithObject:@"Mark"];
NSString *mark2 = mark1;

mark1 mark2;

! , . [[NSArray arrayWithObject:@"Mark"] indexOfObject:@"Mark"] , [[NSArray arrayWithObject:@"Mark"] indexOfObject:textField.text] , textField.text "Mark".

... , indexOfObject: indexOfObject: isEqual: , [self.txtSubCategory.text isEqual: @ "Mark" ]. .. , indexOfObject:

-1

Just guessing the origin of the number is a conversion with a bad integer. This probably meant a return of -1. A.

This type leads me to believe that you may have discovered some kind of error in the base libraries / languages.

-2
source

Source: https://habr.com/ru/post/1782683/


All Articles