Search code examples
iosswiftswift3uibutton

Error: Type 'UIButton.ButtonType' has no member 'submit'


I was asked to try and get an old repository for an iOS app to compile, and am getting this error from the below code:

//SubmitButton.swift
@objc enum ButtonType: Int {
    case submit
    case response
    case accept
    case decline
    case label
    case survey
    case create
}

class SubmitButton: UIButton {
    private let source: [ButtonType: [String]] = [.submit: ["Submit consult", "Submitting", "consult submitted"],
                                                  .accept: ["Accept consult", "Accepting", "consult accepted"],
                                                  .decline: ["Decline consult", "Declining", "consult declined"],
                                                  .response: ["Reply"],
                                                  .survey: ["Report Outcome", "Submitting", "Outcome reported"],
                                                  .create: ["New consult", "Creating New consult", "New consult"]]
    public var type: ButtonType

...
...
...
}

Using Xcode 10.0, app is written in swift 3.

Unfortunately I don't know Swift and this is my first encounter with an iOS app. Figured I'd ask on here...


Solution

  • When using ButtonType inside SubmitButton the code is referring to the predefined UIButton.ButtonType which is not the enum that we see in the code above.

    Please rename the ButtonType enum to a different name and it should work:

    //SubmitButton.swift
    @objc enum CustomButtonType: Int {
        case submit
        case response
        case accept
        case decline
        case label
        case survey
        case create
    }
    
    class SubmitButton: UIButton {
        private let source: [CustomButtonType: [String]] = [.submit: ["Submit consult", "Submitting", "consult submitted"],
                                                      .accept: ["Accept consult", "Accepting", "consult accepted"],
                                                      .decline: ["Decline consult", "Declining", "consult declined"],
                                                      .response: ["Reply"],
                                                      .survey: ["Report Outcome", "Submitting", "Outcome reported"],
                                                      .create: ["New consult", "Creating New consult", "New consult"]]
        public var type: CustomButtonType
    }