tableView:cellForRowAtIndexPath: should return a UITableViewCell and cannot return nil . Therefore you need to remove return nil . But that will not be enough. Your if else should also be completed. This means that all possible section values should be provided, or at least sent to the passage.
Your if else should look like this:
if indexPath.section == 0 { } else if indexPath.section == 1 { } else { }
Or like this:
if indexPath.section == 0 { } else { }
However, the following if else not complete:
if indexPath.section == 0 { } else if indexPath.section == 1 { }
In this case, tableView:cellForRowAtIndexPath: will not know what to return if any of these conditions are checked. Thus, if you try, Xcode (smart) will also display an error message:
There is no return in a function that should return a 'UITableViewCell'
Therefore, the following code should work:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { if indexPath.section == 0 { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell cell.textLabel?.text = self.section1[indexPath.row] cell.accessoryType = .DisclosureIndicator return cell } else { let cell = tableView.dequeueReusableCellWithIdentifier("SwitchViewCell", forIndexPath: indexPath) as SwitchViewCell cell.cellLabel?.text = self.section2[indexPath.row] return cell } }
PS:
If you also use the switch inside your tableView:cellForRowAtIndexPath: method to set your cells, this answer to a similar question may help you.
source share