Search code examples
iosswiftswift3xcode8multipeer-connectivity

'Error' is ambiguous for type lookup in this context Multipeer Connectivity


I get this error after updating to XCode8/Swift 3

'Error' is ambiguous for type lookup

How to fix this error?

Thank you!


Solution

  • This is most common inside of a type that has its own Error type. For example:

    class MyClass {
        enum Error {
            ...
        }
        ...
    }
    

    This can also happen if you've declared an Error type globally. Prior to Swift 3, this was no problem, but in Swift 3 it collides with the new stdlib Error type. To fix it, you either need to change your Error type's name, or (more commonly), just be explicit about which module you're pulling from. So this line of code would become:

    ... withError error: Swift.Error?) {