Objective-c: Comparing two strings not working correctly.
- by Mr. McPepperNuts
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
if(tempArray != nil){
for (int i = 0; i < [tempArray count]; i++)
{
if([[sectionInfo indexTitle] isEqualToString:[tempArray objectAtIndex:i]])
// if([sectionInfo indexTitle] == [tempArray objectAtIndex:i])
{
NSLog(@"found");
break;
} else
{
NSLog(@"Not found %@", [sectionInfo indexTitle]);
[tempArray addObject:[sectionInfo indexTitle]];
NSLog(@"array %@", tempArray);
return [tempArray objectAtIndex:i];
}
}
}
}
The comparison of the strings in the if statement never resolves to true. The sample data has two instances of duplicates for testing purposes. The commented line is an alternate, although I believe incorrect, attempt to compare the section with the string in the tempArray.
What am I doing incorrectly?
Also, all data is in capital letters, so the comparison is not a matter of lower to upper case.