Objective-c: Comparing two strings not working correctly.
Posted
by Mr. McPepperNuts
on Stack Overflow
See other posts from Stack Overflow
or by Mr. McPepperNuts
Published on 2010-06-08T15:10:15Z
Indexed on
2010/06/08
15:12 UTC
Read the original article
Hit count: 179
objective-c
- (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.
© Stack Overflow or respective owner