Ambiguous use of 'encode(_:forKey:)'

Hello,

Im trying to save a custom object into coredata and it works fine on iOS but when trying to run the same code on the Mac Catalyst version of my app I get an error

Ambiguous use of 'encode(_:forKey:)'

I created a class for the object. I made it type NSObject & NSSecureCoding. I tried to make it encode and decode and save to CoreData with a transformer. Works on iOS version of my app but not macOS. Why is that?

Ty

Post not yet marked as solved Up vote post of KrtNthnyLn Down vote post of KrtNthnyLn
962 views
  • I just enabled Catalyst in my app and encountered the same issue. Did you find a solution?

  • No I didnt pursue this further

Add a Comment

Replies

Apparently, there's a long standing bug in Xcode there: https://stackoverflow.com/questions/64892915/ambiguous-use-of-objectforkey-in-xcode-12

They provide a workaround.

You may also look here: https://stackoverflow.com/questions/64253460/looking-for-a-fix-for-swift-ambiguous-use-of-objectforkey

Hope that helps.

  • Thanks for the suggestion I’ll check it out.

  • The links didn't help. If I try to encode CGfloat, CGPoint or CGSize in macOS I get this roadblock, in iOS it works. All other types of values, Int, Date, Double work as expected.

Add a Comment