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

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

我被要求尝试获取旧存储库以供 iOS 应用程序编译,但我从以下代码中收到此错误:

//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

...
...
...
}

使用Xcode 10.0,app写在swift 3.

很遗憾,我不知道 Swift,这是我第一次接触 iOS 应用程序。我想我会在这里问...

当在 SubmitButton 中使用 ButtonType 时,代码指的是预定义的 UIButton.ButtonType,这不是我们在上面的代码中看到的枚举。

请将 ButtonType enum 重命名为其他名称,它应该可以工作:

//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
}