I am getting this error when I analize my ios project
The left operand of '==' is a garbage value
this is what the code looks like where its occurring.. This method is used to sort the array I have that is returned to me from the DB.
- (NSMutableArray *)startSortingTheArray:(NSMutableArray *)unsortedArray
{
[unsortedArray sortUsingComparator:^ NSComparisonResult(SearchResultItem *d1, SearchResultItem *d2) {
//initalize comparison
NSComparisonResult result;
NSInteger manufacturerID1 = d1.manufacturerID;
NSInteger manufacturerID2 = d2.manufacturerID;
if (manufacturerID1 > manufacturerID2)
return NSOrderedAscending;
if (manufacturerID1 < manufacturerID2)
return NSOrderedDescending;
if (manufacturerID1 == manufacturerID2) {
NSString *model1 = d1.model;
NSString *model2 = d2.model;
result = [model1 localizedCompare:model2];
}
if (result == NSOrderedSame) {
//..
The compiler is complaining because it believes it’s possible to reach the
==comparison beforeresulthas a value.The best option given your code is to use
else ifandelse:Or you could do this:
Or even this:
This way the compiler knows that if the comparison is reached, the value of
resultwill already have been set.