问题标签 [nspersistentstore]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
294 浏览

core-data - Why is NSPersistentStoreCoordinator not recognizing my managed object model?

I am trying to create a CoreData store with iCloud. Following the example code in iCloud Programming Guide for Core Data, I have this piece of code:

This is the image of my managed object model

enter image description here

I'm getting an error: Use of undeclared identifier 'salonbook'.

Why?

0 投票
0 回答
75 浏览

ios - 核心数据 - 迁移到新模型名称

我现在正在更新商店中有一个应用程序。我做了很多核心数据更改,包括更改“lazy var managedObjectModel: NSManagedObjectModel”和“lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator?”中的名称。

如何正确使用 Core Data Migration 来确保现有用户下载更新时,应用不会在他们身上崩溃?

0 投票
1 回答
66 浏览

objective-c - I create a file using NSPersistentStoreCoordinator, but it's not found after app restart

I am trying to do a backup/restore of my Core Data store; in my app, I create the file, do a fileExistsAtPath and the file is there. When I use Finder, it's not there. This is the code (which I copied and modified, so the style and duplicate naming is not mine; probably should start all over again) to create the backup:

UPDATE The code is here...

This is the console output:

currentURL is file:///Users/spokanedude/Library/Developer/CoreSimulator/Devices/1EE69744-255A-45CD-88F1-63FEAD117B32/data/Containers/Data/Application/41B5E165-C3E2-4D8A-81EB-98ADB20B8B0D/Documents/saori.sqlite 2015-01-20 10:41:36.042 SalonBook[84743:2055509]

backup file URL to use is file:///Users/spokanedude/Library/Developer/CoreSimulator/Devices/1EE69744-255A-45CD-88F1-63FEAD117B32/data/Containers/Data/Application/41B5E165-C3E2-4D8A-81EB-98ADB20B8B0D/Documents/saori.backup-20153920103944

2015-01-20 10:41:36.042 SalonBook[84743:2055509]

currentCoreData exists 2015-01-20 10:41:36.042 SalonBook[84743:2055509]

backupFile exists 2015-01-20 10:41:36.042 SalonBook[84743:2055509]

target file exists 2015-01-20 10:41:36.092 SalonBook[84743:2055509] current store file removed

2015-01-20 10:41:36.125 SalonBook[84743:2055509] replaced current store file successfully

2015-01-20 10:41:36.126 SalonBook[84743:2055509] store Options are { NSSQLitePragmasOption = { "journal_mode" = WAL; }; } 2015-01-20 10:41:36.127 SalonBook[84743:2055509] addPersistentStoreWithType completed successfully...

2015-01-20 10:41:36.127 SalonBook[84743:2055509] STORE FILE is /Users/spokanedude/Library/Developer/CoreSimulator/Devices/1EE69744-255A-45CD-88F1-63FEAD117B32/data/Containers/Data/Application/41B5E165-C3E2-4D8A-81EB-98ADB20B8B0D/Documents/saori.sqlite

When I do the backup, it says the file is there; when I use ForkLift (a Finder replacement) it shows up (sometimes); when I do the restore, it finds the file and says the restore was successful, but instead it wipes out the existing data, like the file contents were missing. Can't figure this out for the life of me... help would be appreciated.

0 投票
1 回答
103 浏览

objective-c - 删除和重新创建核心数据存储的正确方法

我想确认我删除核心数据存储(sqlite)的方法是正确的。它似乎可以正常工作而不会崩溃,但想确认这是正确的方法。之后,当用户连接到数据库时,会自动生成一个新的 sqlite 文件。

这是我删除数据存储的代码:

0 投票
1 回答
97 浏览

ios - 当商店位置相同时如何处理 NSPersistentStoreCoordinatorStoresWillChangeNotification

我正在使用 Core Data + iCloud 并获得不少 NSPersistentStoreCoordinatorStoresWillChangeNotifications,其中旧商店和新商店的 URL 是相同的。我只使用一台设备,并且在运行我的应用程序时会发生几次。

如果商店 URL 没有更改,并且设备是唯一一个将数据持久保存到商店的设备,为什么它会发出这些通知?当新旧 URL 相同时,是否可以忽略这些通知?

这是通知的 userInfo 字典的内容:

}}

0 投票
0 回答
150 浏览

ios - 受影响的商店对获取未保存的 NSManagedObjects 的影响?

这是一个简短的序列,涉及一个带有(最初为空的)NSManagedObjectContextNSPersistentStoreCoordinator带有两个NSPersistentStores 的 Core Data 堆栈:

这会吸引一名玩家。如果我取消注释(2)(即涉及第二家商店)它会获取零个(原文如此!)玩家。如果我也取消注释(1)它会再次获取一名玩家。

因此,似乎该行为仅在以下情况下才NSFetchRequest返回 unsaved NSManagedObjects

  1. 要么affectedStoresnil并且这些对象尚未分配给任何商店
  2. affectedStores不是nil,并且这些对象已分配给受影响的商店

确实是这样吗?如果是这样,Apple 在哪里记录了这一点?

0 投票
2 回答
796 浏览

ios - Referring to NSPersistentStore instances created in AppDelegate

I modified the boilerplate core data stack code you get with a core data application to add two NSPersistentStores to the NSPersistentStoreCoordinator instead of just one.

I need to specify the store when adding NSManagedObject objects like below.

And specifying the stores which I need to fetch data from like this.

My question is how can I get a reference to those NSPersistentStores created in the AppDelegate?

Just to be clear, I already know how to get a reference to the AppDelegate itself.

It's the getting the NSPersistentStore part is where I'm stuck.


I tried creating it as a separate property in the AppDelegat like this but I don't know how to call it/add it from persistentStoreCoordinator.

Besides whenever I call this property, wouldn't it add a new instance of a store to the coordinator?

0 投票
1 回答
207 浏览

ios - 将核心数据堆栈更新到 applicationWillEnterForeground

我在两个应用程序之间共享了相同的 .sqilte App groups

当我在 App A 中添加录音并打开 App B(首次启动)时,App B 会正确检索数据。

我想在应用程序 A 和应用程序 B(已经在后台启动)中添加录音时同步数据,应用程序 B 可以在它回到前台时检索数据。

这就是为什么当 App B 回到前台时,我将 Core Data Sack 更新为 applicationWillEnterForeground。哪种方式是正确的?

不幸的是,它不能按我的意愿工作。当我进入 applicationWillEnterForeground 时,每次都会对检索到的数据进行配音。哪种方式是正确的?

// 编辑 2014/04/17 : 尝试使用 Mundi 的解决方案

我试过了NSManagedObjectContextObjectsDidChangeNotification

mergeContextChangesForNotification已被调用,但我从未进入过这种情况:if otherContext != managedObjectContext) && (otherContext.persistentStoreCoordinator == managedObjectContext.persistentStoreCoordinator

0 投票
0 回答
70 浏览

objective-c - 单个商店同时使用多个 NSPersistentStoreCoordinator

我正在为我的应用程序开发 iWatch 应用程序。现在我已经对其进行了编码,以便核心数据存储(sqlite 文件)位于共享组文件夹中,以便我可以访问 iWatch 扩展、今天的扩展和共享照片扩展中的数据。现在我在 iWatch 扩展中创建了 NSPersistentStoreCoordinator 的新对象,但问题是在 iWatch 打开时 iPhone 应用程序所做的更改不会显示在 iWatch 中,直到我重新运行 IWatch 应用程序。任何想法是什么问题。

0 投票
1 回答
83 浏览

ios - 使用 Core Data + RestKit 0.2.x 自动删除和重新创建持久数据存储

在开发我的应用程序的早期阶段,Core DataRestKit经常大量修改数据模型,发现很少或根本没有考虑迁移。

我希望逻辑是:

我现在有什么,老实说,我不明白......

但基本上,我真正想知道的是 - 这不是一个足够普遍的问题(必须不断重置虚拟设备),有一种方法可以告诉Core Data它只是把它炸毁吗?

如果没有,我错过了这个阻止上述算法实现的操作的复杂性?