1

I'm new to "Magical Record" and pretty new to iOS programming in general. I'm just trying to get things set up. I've followed the instructions in http://yannickloriot.com/2012/03/magicalrecord-how-to-make-programming-with-core-data-pleasant/, but instead of:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [MagicalRecordHelpers setupCoreDataStackWithStoreNamed:@"MyDatabase.sqlite"];
    // ...
    return YES;
}

I think I'm using a newer version which changes the AppDelegate to:

@implementation LSAppDelegate
@synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    [MagicalRecord setupCoreDataStackWithStoreNamed:@"MyDatabase.sqlite"];
    return YES;
}

- (void)applicationWillTerminate:(UIApplication *)application{
    [MagicalRecord cleanUp];
}
@end

When running, I get a SIGABRT at:

+ (NSManagedObjectModel *) MR_mergedObjectModelFromMainBundle;
{
    return [self mergedModelFromBundles:nil];
}

The stack trace looks like:

#0  0x00011f7e in +[NSManagedObjectModel(MagicalRecord) MR_mergedObjectModelFromMainBundle] at /Developer/projects/demo/MagicalRecord/Categories/NSManagedObjectModel+MagicalRecord.m:33
#1  0x00011eb4 in +[NSManagedObjectModel(MagicalRecord) MR_defaultManagedObjectModel] ()
#2  0x000147ca in +[NSPersistentStoreCoordinator(MagicalRecord) MR_coordinatorWithSqliteStoreNamed:withOptions:] ()
#3  0x000148fa in +[NSPersistentStoreCoordinator(MagicalRecord) MR_coordinatorWithSqliteStoreNamed:] ()
#4  0x00016546 in +[MagicalRecord(Setup) setupCoreDataStackWithStoreNamed:] ()
#5  0x000026eb in -[LSAppDelegate application:didFinishLaunchingWithOptions:] ()

I have no idea what I did wrong or what I can do to fix it. Any ideas?

4

1 回答 1

2

听起来您在核心数据迁移方面遇到了问题。从模拟器中卸载应用程序将强制使用新的 SQLite 数据库,这在您在开发期间更改架构时很方便。

稍后,您可能希望切换到-setupCoreDataStackWithAutoMigratingSqliteStoreNamed,只要您创建托管对象模型的新版本,它就可以处理琐碎的迁移。有关如何创建这些版本的信息, 请参阅模型文件格式和版本。

于 2012-07-11T18:56:05.860 回答