English 中文(简体)
移民散居区iOS
原标题:Lightweight Migration hassle iOS

i am having a bit of a hassle, i created a new version of my context & made it the default one, after that i changed my code according to the apple docs and it looks like that now:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{

    if (persistentStoreCoordinator != nil)
    {
        return persistentStoreCoordinator;
    }
    NSError *error = nil;
    persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"database.sqlite"];
    NSPersistentStoreCoordinator *psc = persistentStoreCoordinator;
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                             [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                             [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];


    BOOL success = [psc addPersistentStoreWithType:NSSQLiteStoreType
                                     configuration:nil URL:storeURL
                                           options:options error:&error];
    if (!success) {
        NSLog(@"Unresolved Error");
        abort();
    }

    return persistentStoreCoordinator;
}

但我有一个错误, 即使它是 1:1 1 相同的代码, 在行 < code> BOOL 省略 中, i 得到一个 < code> noccolable 指针到 NSPersistentstore 的整数转换 BOOL 到 NSPersistentstore

地图虽然有效,但我得到了新模型, 可以说5次中4次是有效的, 5次是出错的。

任何想法 如何修复它?

<强 > UPDATE i 修改代码稍稍修改,现在看起来是这样的

NSPersistentStore *store = [psc addPersistentStoreWithType:NSSQLiteStoreType
                                     configuration:nil URL:storeURL
                                           options:options error:&error];
if (!store) {
        NSLog(@"Unresolved Error");
        abort();
}
最佳回答

警告和误差是两回事。

警告是,您正在将指针当作一个数字处理。 addPersistentStoreWornType: configation:URL:options:error 不返回一个 BOOL (基本上是一个数字), 它返回您正在创建的 NSPististentStore 对象。 您应该将结果指定给一个 NSPistentStore {/code> 变量, 而不是布林成功变量。

如果失败, 它返回 < code> nil , 并充填 < code> eror 对象。 您可以从此对象获取关于错误的更多信息, 如登录其 < code > 本地化描述

问题回答

暂无回答




相关问题
Copy data from Access to SQL

I am in the process of migrating an existing Access database to a SQL database with a web front-end. I have successfully copied the database to SQL using the SQL Server Migration tool and am working ...

MongoMapper and migrations

I m building a Rails application using MongoDB as the back-end and MongoMapper as the ORM tool. Suppose in version 1, I define the following model: class SomeModel include MongoMapper::Document ...

Switching to WPF. Is it time?

I m considering switching from MFC to WPF. My first concern is that there are too many users who don t have .NET with WPF installed yet. Can anybody point to a source containing the WPF penetration ...

rake db:migrate running all migrations correctly

I m fairly new to Ruby on Rails here. I have 2 migrate files that were provided. The first one, prefixed with 001, creates a table and some columns for that table. The next migrate file, prefixed ...

Migrate Java Applet to what/where?

I am reviewing currently a medium size code base (around 30K LOC) which uses a huge Applet and interfaces with other systems. It s a tool to create custom labels, so we need drag-n-drop and other ...