I have a UITableViewController
with a private enum
called IndexPath
as a nested type.
class SettingsViewController: UITableViewController {
enum IndexPath {
case Gender, Weight, EmergencyContact
var tuple: (Int, Int) {
switch self {
case .Gender:
return (0, 0)
case .Weight:
return (0, 1)
case .EmergencyContact:
return (1, 0)
}
}
}
}
The point of this is so that inside my cellForRowAtIndexPath
, I can simply put the section and row in a tuple and make a switch statement to match the enum values. That way, I get to do customise the cell as I should for that index path:
switch (indexPath.section, indexPath.row) {
case IndexPath.Gender.tuple:
// Do something.
case IndexPath.Weight.tuple:
// Do something.
case IndexPath.EmergencyContact.tuple:
// Do something.
default:
break;
}
However, I keep getting a compiler error Binary operator ~= cannot be applied to two (Int, Int) operands
on the lines where the switch cases are. Any idea what that means? I'm not even aware of an operator ~=
and neither am I explicitly using it.
Do this.
switch (indexPath.section, indexPath.row) {
case (IndexPath.Gender.tuple.0, IndexPath.Gender.tuple.1):
// Do something.
case (IndexPath.Weight.tuple.0, IndexPath.Weight.tuple.1):
// Do something.
case (IndexPath.EmergencyContact.tuple.0, IndexPath.EmergencyContact.tuple.1):
// Do something.
default:
break;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.