Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Object' is ambiguous for type lookup in this context in Xcode 9

I want to update my app for iOS 11, and have this issue. This is my current code:

protocol DataSourceDelegate: class {
    associatedtype Object

    func cellIdentifierForObject(object: Object) -> String
    func swipeToDeleteObject(object: Object)
}

This protocol is used in one of my view controller:

extension TransactionsViewController: DataSourceDelegate {
    func cellIdentifierForObject(object: Object) -> String {
        return "Cell"
    }

    func swipeToDeleteObject(object: Object) {
        object.managedObjectContext?.performChanges {
            object.managedObjectContext?.delete(object)
        }
    }
}

Now I get this error for the Object type:

'Object' is ambiguous for type lookup in this context

On this line:

func cellIdentifierForObject(object: Object) -> String { ... }

For my this issue appears because there are some other Object type in my project. I tried to put the protocol or class name in front of the name, but I still get error.

like image 261
Adrian Avatar asked Aug 08 '17 10:08

Adrian


Video Answer


2 Answers

In my case, I had this ambiguity because the class was declared in a swift file and also being auto-generated by my data model.

If you already declare your class in a swift file, then make sure the code generation is disabled for it.

  1. Select your entity in your xcdatamodeld
  2. Open the third tab, Data Model inspector:
    enter image description here
  3. Set Codegen to Manual/None
    enter image description here
like image 198
Cœur Avatar answered Sep 22 '22 13:09

Cœur


For me the cause of the error was same name of the Class for two different Cocoapods. If you are integrating pods to your VC, try to delete some of them by clearing 'Import ...' line at the top of your VC file.

like image 32
Anton Klimenko Avatar answered Sep 19 '22 13:09

Anton Klimenko