简体   繁体   中英

This code will never be executed warning swift equatable enum

I have this code from a 3rd party library:

public enum NoError: Swift.Error, Equatable {
    public static func ==(lhs: NoError, rhs: NoError) -> Bool {
        return true
    }
}

This generates the warning : 1. 'lhs' is uninhabited, so this function body can never be executed This will never be executed

How could I get rid of this warning?

enum should have case . I mean enumeration should have definition. I don't understand why enum uses here, because it's can be class . However, this will work without warnings:

public enum NoError: Swift.Error, Equatable {

    case case1
    case case2

    public static func ==(lhs: NoError, rhs: NoError) -> Bool {
        return true
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM