The following Objective-C statement does not work correctly.
cell.templateTitle.text=[(NSDictionary*) [self.inSearchMode?self.templates:self.filteredTemplates objectAtIndex:indexPath.row] objectForKey:@"title"];
However, if I split it into an if()
statement it works fine.
if(self.inSearchMode){
categorize=[(NSDictionary*)[self.filteredTemplates objectAtIndex:indexPath.row] objectForKey:@"categorize"];
} else {
categorize=[(NSDictionary*)[self.templates objectAtIndex:indexPath.row] objectForKey:@"categorize"];
}
What are the limitations of using the ternary operator in Objective-C? In other languages like C# the above ternary statement would have worked correctly.
My guess is that it's an order of operations issue. Have you tried:
[(self.inSearchMode?self.templates:self.filteredTemplates) objectAtIndex:indexPath.row]
(notice added parens)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With