Overriding class to amend button action?

I have a function that automatically creates buttons and inputs them into an array. However, the "FUNCTION1" button action is static and no matter the logic I implement I cannot make it execute different code.

So I thought that it would be possible to cast the buttons into a new class to ammend it with a new function i.e. "FUNCTION1" substituted for "FUNCTION2" without changing anything else, but I get the error "Property does not override any property from its superclass" and I can't use self.

//initialize vehicle buttons and append to array
func convertVehiclesToButtons(from vehicle: [Vehicles]) {
    for car in vehicles {
        let carButton: CarButton = {
            let carButtonData = CarButton(imageNamed: "carImage", title: "", buttonAction: {
                //FUNCTION 1
            carButtonData.title = car.title
            carButtonData.zPosition = 1
            return carButtonData

//convert car button to van button
func convertParkedCarButton(forButton carButton: CarButton) -> VanButton {
    return carButton as! VanButton

class VanButton: CarButton {
    override var carButton = {
        CarButton(imageNamed: .self, title: "", buttonAction: {
            //FUNCTION 2

I found the problem to be calling one function. If I used the variables to set conditions, then I could use different functions as if they were different buttons, even though it was the same one.

Still, I couldn't figure out how to force cast the button and override the original buttonAction logic.

Terms of Service

Privacy Policy

Cookie Policy