1

i have just set a new version of my app live but on devices that are updating to the new version, the app crashes right after i applicationDidFinishLaunching:WithOptions:. I updated/added some attributes to my CoreData database.

This is the Thread that contains the crash. Any help?

    Date/Time:       2013-03-07 18:14:47.532 +0100
    OS Version:      iOS 6.0 (10A405)
    Report Version:  104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Crashed Thread:  9


0   libsystem_kernel.dylib          0x3b501350 __pthread_kill + 8
1   libsystem_c.dylib               0x3807cfb2 pthread_kill + 54
2   libsystem_c.dylib               0x380b93ea __abort + 90
3   libsystem_c.dylib               0x380b9388 abort + 124
4   distribution                    0x001fed18 -[MOManager persistentStoreCoordinator] + 420
5   distribution                    0x0020000e -[NSThread(DataCore) threadContext] + 274
6   distribution                    0x001fd470 +[KwManagedObject defaultContext] + 44
7   distribution                    0x001fd6f6 +[KwManagedObject countWithPredicate:] + 26
8   distribution                    0x001fd6d6 +[KwManagedObject count] + 18
9   distribution                    0x001b3c46 +[DbThread dbCount] (DbThread.m:31)
10  distribution                    0x001b3d1a -[DbThread main] (DbThread.m:43)
11  Foundation                      0x38e69a3c __NSThread__main__ + 968
12  libsystem_c.dylib               0x3805f0de _pthread_start + 306
13  libsystem_c.dylib               0x3805efa4 thread_start + 4
Fry
  • 922
  • 2
  • 10
  • 24
  • Have you followed the guidance in [Apple's document](https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/Introduction.html) regarding model versioning and migration? – MattP Mar 07 '13 at 20:11
  • Did you enable automatic light-weight migration? See this topic: http://stackoverflow.com/questions/2310216/implementation-of-automatic-lightweight-migration-for-core-data-iphone – Chris Mar 07 '13 at 20:11
  • @chris: no i didnt update automatic light-weight migration. But does this really cause the crash and do i only have to implement light weight-migration to solve this? thx guys – Fry Mar 07 '13 at 20:26
  • Yes, you absolutely have to. I hope you also added a new version of your data model before you made the edits, otherwise there's no way for CoreData to perform the migration. Even changing a property name without adding a new version and letting it do the migration will cause a crash. – Chris Mar 07 '13 at 21:41

1 Answers1

4

When you launch an app which uses CoreData the app creates a sqlite file in (by default) the Documents directory. The contents of this sqlite are described by the CoreData model you did create (xcdatamodeld). When you make changes to your CoreData model (xcdatamodeld) you must migrate your sqlite file with it.

This can be done automatically by CoreData (light-weight migration, check out the docs) when the changes are minor. But when you make major changes you have to make sure the data is migrated manually when an user starts your app after the update. This can be done for example by a migration method you wrote. You have to execute this method before initializing any CoreData objects using the new model.

I recommend you check out the documentation here. Also always test your app before submitting it to the AppStore. Make sure you also 'simulate' an update by installing the adhoc ipa of your previous version on a device, starting the old version, then installing the updated ipa and start the app again.

If you have any questions, feel free to ask.

Robin van Dijke
  • 752
  • 4
  • 13
  • Thanks, so how should the migration method look like and where should i place it? – Fry Mar 08 '13 at 07:14
  • You can do several things: 1) Remove the current user data and create a new store (not the best method because you lose user data) 2) Include the old CoreData model. Read out every object and create a new object in the new store for it. 3) Create a [mapping model](https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmMappingOverview.html#//apple_ref/doc/uid/TP40004399-CH5-SW1) – Robin van Dijke Mar 08 '13 at 07:24