核心数据错误:持久存储协调器中最常见的错误有哪些?

发布于 2024-11-26 21:05:40 字数 1184 浏览 0 评论 0原文

enter code hereIn my Application I am using Sqlite as an externel data base. So, Please Reply.I am using Xcode finding defficult to communicate to the sqlite file and Managed Object Model..


    enter code here



- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (__persistentStoreCoordinator != nil)
    {
        return __persistentStoreCoordinator;
    }

    NSURL *storeURL=[[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"CoreDataBountyHunter.sqlite"];

    NSError *error = nil;
    __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error])
    {

  //     
         Typical reasons for an error here include:
         * The persistent store is not accessible;
         * The schema for the persistent store is incompatible with current managed object model.


        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }    

    return __persistentStoreCoordinator;
}
enter code hereIn my Application I am using Sqlite as an externel data base. So, Please Reply.I am using Xcode finding defficult to communicate to the sqlite file and Managed Object Model..


    enter code here



- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (__persistentStoreCoordinator != nil)
    {
        return __persistentStoreCoordinator;
    }

    NSURL *storeURL=[[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"CoreDataBountyHunter.sqlite"];

    NSError *error = nil;
    __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error])
    {

  //     
         Typical reasons for an error here include:
         * The persistent store is not accessible;
         * The schema for the persistent store is incompatible with current managed object model.


        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }    

    return __persistentStoreCoordinator;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁我热情 2024-12-03 21:05:40

Core Data 不适合与外部 SQLite 数据库一起使用,除非您实现自己的存储。如果您需要具有预定义架构的外部数据库,那么不要尝试将核心数据融入您的解决方案。相反,使用标准 C API 与 SQLite 数据库对话。

Core Data is not intended to be used with an external SQLite database, unless you implement your own store. If an external database with predefined schema is what you need then don't try to fit Core Data into your solution. Instead use the standard C API to talk to your SQLite database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文