简体   繁体   中英

How to change a Struct named Error to implement Error protocol in swift

I have a struct named 'Error' and I want to implement 'Error' protocol in struct. I did

public struct Error: Codable, Error {
}

But I get error

 error: inheritance from non-protocol type 'Error'
public struct Error: Codable, Error {

Is there a way to add a namespace to specify the Error protocol in swift?

Thank you.

For native Swift types, you can prepend Swift. to the type to tell the compiler to use the native type instead of your own.

In your case, you would do this:

public struct Error: Codable, Swift.Error {
    // ...
}

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