2

I am working on an app that fetches data from an API, turns that into Core Data Managed Object by first converting to a dictionary and finally iterating over every object and saving it synchronously from the main thread.

I am working with a large dataset so the number of objects could be in thousands, and this procedure works for the most part. But in some cases, say 1 in every 4 trial, the app crashes with the following error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -_referenceData64 only defined for abstract class. 

I have been trying to solve it for some time but with no luck. I am thinking it has something to do with the main thread and I tried saving it from a background thread but that didn't work either and as per the apple documentation, the context can only be referenced from the main thread.

I would really appreciate it you guys could help me out here. Thanks in advance to all of you.

Mozz
  • 318
  • 2
  • 8
  • 1
    It sounds like you are moving managed object instances between threads. https://stackoverflow.com/questions/2009399/cryptic-error-from-core-data-nsinvalidargumentexception-reason-referencedata6 – Paulw11 Jan 01 '21 at 21:05
  • Thanks for the feedback. I read the post you shared already but its in Objective-C so kinda having hard time decoding it. – Mozz Jan 01 '21 at 21:10
  • It doesn't really matter about that code. Check your code to make sure you aren't moving managed objects across threads. That is quite an old solution anyway. You can now use parent/child contexts. You can read about core data threading and concurrency in the Apple documentation. https://developer.apple.com/documentation/coredata/using_core_data_in_the_background – Paulw11 Jan 01 '21 at 21:12
  • Yeah thanks man! I think I solved it. I was making some calls from the background thread, moving everything to the main thread solved the issue. – Mozz Jan 01 '21 at 22:53

0 Answers0