1
votes
struct SubSection {
    let title:String
    var options: [SubSettingsOptionType]
}

enum SubSettingsOptionType {
    case staticCell(model:SubSettingsOption)
    case switchCell(model:SubSettingsSwitchOption)
}

class SubSettingsSwitchOption {
    let title:String
    let handler: (() -> Void)
    let isOn:Bool
    
    init(title:String, _ mHandler:@escaping (() -> Void), isOn:Bool) {
        self.title = title
        self.isOn = isOn
        self.handler = mHandler
    }
}

class SubSettingsOption {
    var title:String
    var isSelected:Bool
    var handler: ((Int, Int) -> Void)
    
    init(title:String, isSelected:Bool, _ mHandler:@escaping ((Int, Int) -> Void)) {
        self.title = title
        self.isSelected = isSelected
        self.handler = mHandler
    }
}

I came across a code with a complex structure for me as above When I try to access and use this code, I am using the following, but it is very inconvenient every time I use it. Is there an easier way to access the data?

thank you so much for reading

let type = models[0].options[0]
switch type.self {
case .staticCell(let model):
    model.isSelected = true
case .switchCell(let model):
    model.handler()
}