Skip to content

When using Switch to determine the Enum of @ objc, add a default prompt #67195

Open
@Zero-Cjh

Description

@Zero-Cjh
@objc public enum TestEnum: Int { 
    case first = 1 
    case second = 2 
    var strValue:String { 
        switch self {
        case .first: 
            return "first"
        case .second:
            return "second"
    }
}

func getStrValue(_ value: TestEnum) -> String {
    return value.strValue
}

If I am using on ObjC

NSLog(@"%@", getStrValue(3));

There are no error prompts during the compilation phase
Crash may occur during the operation phase

Can we detect and predict this error during the compilation phase, and prompt to add default in the Switch

Metadata

Metadata

Assignees

No one assigned

    Labels

    @objcFeature → attributes: The @objc attributecompilerThe Swift compiler itselfdeclarationsFeature: declarationsenumFeature → type declarations: Swift enumeration declarationsfeatureA feature request or implementationobjective-c interopFeature: Interoperability with Objective-Craw-value typesFeature → declarations → enum: A raw-value type of an enumeration

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions