CoreData Ambiguous reference to member 'id' Xcode 12

Viewed 961

I have a coredata entity with an attribute id of type String

when trying to reference that attribute from a key path it throws an error

let path = #keyPath(User.id) //Ambiguous reference to member 'id'

the codegen is set to Class Definition.

I tried to check the generated file for the class and I found that the entity class now confirms to Identifiable which requires id

I noticed that setting the deployment target to anything lower than iOS 13 will fix the issue (but I don't want to do that)

Xcode Version 12.0 beta 4 (12A8179i)

Is there a way to fix this without disabling codegen or changing the deployment target?

1 Answers

Just a work around for this issue is to use the Objective c string presentation of the key path needed.

for example if you want to create a predicate for the id then instead of

let ambiguousPredicate = NSPredicate(format: "%K = %@", #keyPath(User.id), id) 

you can write

let workingPredicate = NSPredicate(format: "%K = %@", (\User.id)._kvcKeyPathString!, id)
Related