Xcode thinks control may reach end of non-void function due to returns in if/else statements
if-statement, objective-c, return
Solution
You do have a condition that results in no return:
if `shouldDisplayExtra` exist and `cellType == kExtraCellTypeNone` then there is no return defined...
You should add an else block to the conditional:
if (cellType != kExtraCellTypeNone) {
[cellsToContainExtra setValue: [NSNumber numberWithInt: cellType] forKey: lineIDString];
return lineSize.height + actorSize.height + 200;
} else {
// return something here
}
Problem
This is a simple question: why does the following code cause a "Control may reach end of-non-void function" warning? Under what circumstances would one of the two return statements not be hit? Would it be more standard coding practise to place the second `return` statement outside of the `else` block? This does silence the warning, but I'm curious as to why it exists at all. ``` - (CGFloat) tableView: (UITableView *) tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath { NSString *lineToFit = [[self.fetchedResultsController objectAtIndexPath: indexPath] line]; NSString *actorToFit = [[self.fetchedResultsController objectAtIndexPath: indexPath] actor]; CGSize lineSize = [lineToFit sizeWithFont: [UIFont boldSystemFontOfSize: 12.0f] constrainedToSize: CGSizeMake(320, 800)]; CGSize actorSize = [actorToFit sizeWithFont: [UIFont boldSystemFontOfSize: 12.0f] constrainedToSize: CGSizeMake(320, 800)]; if (shouldDisplayExtra) { kExtraCellType cellType = [self cellIsGoingToContainExtraView]; if (cellType != kExtraCellTypeNone) { [cellsToContainExtra setValue: [NSNumber numberWithInt: cellType] forKey: lineIDString]; return lineSize.height + actorSize.height + 200; } } else { // Return the line height, actor height, plus a buffer. return lineSize.height + actorSize.height; } } ```