0

I am using core data with preloaded sqlite database. I am encountering a strange issue, the app works on the simulator, but when I try run it on a device, e.g. iPad, I get the error below.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSManagedObject persistentStore]: unrecognized selector sent to instance 0x3bebf50' 

I recreated the sqlite database from the model and repopulated the database, but I still get the same error. I've checked the 'Compiled Sources' and 'Copy Bundle Resources' in the build phase section and the files are all there.

Code: http://pastebin.com/fTTgEA3W

Been racking my brain and can't seem to understand why it's not working, any help would really be appreciate.

Thank you for your time and if you need any more information please let me know.

JingJingTao
  • 1,760
  • 17
  • 28

1 Answers1

0

First measure: delete the app and reinstall.

Second measure: text search for a call to persistentStore in your code. It is apparently going to an address that is a NSManagedObjectContext which does not have this method. Fix the error if you find it.

Third measure: review your recreation algorithms to make sure you are building the store correctly. In my projects with big stores, I usually have a SETUP flag that I switch on if the store needs to be imported from raw data, which normally works only in the simulator because of the memory needs. (When SETUP is off and there is no store, the one generated previously is copied over.) Maybe on the iPad you do not have enough memory to do the data import.

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • Thanks for you help. I am trying out your steps. "Maybe on the iPad you do not have enough memory to do the data import." Would that mean I need to decrease the number of rows in the database or use different values for the methods, setFetchOffset, setFetchLimit, setFetchBatchSize? – JingJingTao Apr 05 '12 at 12:03
  • No, I mean that you do the raw data import on the simulator to prepare the big SQLite database. You can then copy that over to the iPad (program's documents directory) when the app is run the first time. – Mundi Apr 05 '12 at 15:52
  • Hi Mundi, sorry for the late reply. I think the problem is that the tableview is trying to load to many records and there is a memory issue, if I use setFetchLimit, say equal to 100, then it works. Also I still don't really understand what you are suggesting, I currently add the preloaded database to the project and copy to the program's document directory(logic in my persistent store method of my app delegate). I don't know we're on the same page yet, thank you for your help, please explain your point more if necessary, I quiet new to iOS development, so maybe I am missing something. – JingJingTao Apr 17 '12 at 09:47
  • OK, I was just referring to how to populate your database at first. But you are already doing that - so no problem. What you say about the table view is not true. If you follow the Apple examples and use a `NSFetchedResultsController` the memory management is great - nothing else to do for you. A table view will only have memory problems if you use your own array as the `datasource`, which is bad design in this case. – Mundi Apr 17 '12 at 10:17
  • So for example, even if my fetchResultasController gets 100000+ records and populates the search results tableview with those records, it won't cause any memory issues, it will probably just be very slow? Or say a fetchResultsController populates my tableview with 100k records, this will not cause a memory issue? If so, then thanks for clearing that up with me. – JingJingTao Apr 17 '12 at 10:36
  • It will not even be slow! No memory issues. It will be constrained only by the SQLite engine (which is extremely fast) and the graphic drawing if you have complex cells. -- Please tick the checkmark above if it helped you! – Mundi Apr 17 '12 at 14:52