Thursday, August 11, 2022
HomeiOS Developmentios - Methods to repair closure "expects 1 argument, however 2 had...

ios – Methods to repair closure “expects 1 argument, however 2 had been utilized in closure physique” when utilizing enumerated().map

[ad_1]

I’ve the next Swift code which makes use of enumerated().map to index my modeStrings:

let modeNames = [
            "Rest: ",
            "Misbalanced: ",
            "Left Charged: ",
            "High Voltage: ",
            "High Temperature: ",
            "Low Temperature: ",
            "Low Voltage: ",
            "Hibernation: ",
            "Over Discharge Current: ",
            "Ship: "
        ]
        var modeStrings = [
            deviceData.restMode,
            deviceData.misbalancedMode,
            deviceData.leftChargedMode,
            deviceData.highVoltageMode,
            deviceData.highTempMode,
            deviceData.lowTempMode,
            deviceData.lowVoltageMode,
            deviceData.hibernationMode,
            deviceData.overDischargeMode,
            deviceData.shipMode
        ]
        
        let indexAndNum = modeStrings.enumerated().map { (index: Int, component: inout String?) in
            let worth: String
            if Int(knowledge[28 + index]) == 1 {
                worth = "On"
            } else {
                worth = "Off"
            }
            let formattedString = (modeNames[index] + worth)
            component = formattedString
        }
    }

My drawback is I get an error Contextual closure sort '(EnumeratedSequence<[String?]>.Ingredient) throws -> ()' (aka '((offset: Int, component: Elective<String>)) throws -> ()') expects 1 argument, however 2 had been utilized in closure physique

This error goes away if I take away the inout key phrase however then I get this error: Can't assign to worth: 'component' is a 'let' fixed.

component is referring to my modeStrings which is of the kind [String?]. How can I assign a worth to component with out utilizing inout? Or am I simply utilizing inout incorrectly?

[ad_2]

RELATED ARTICLES

Most Popular

Recent Comments