NSIncrementalStore以纯英语解释 [英] Explanation of NSIncrementalStore in plain english

查看:350
本文介绍了NSIncrementalStore以纯英语解释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在看到 NSIncrementalStore ,因为我一直在研究使用核心数据与网络服务交互的最佳方式。



阅读 Drew Crawford的文章编程指南类参考 和本教程每次我多次仍然在努力理解 NSIncremental 商店是什么,为什么和什么时候使用它。



在阅读mundi的回答后,我可以看到一些进一步的上下文。

我正在研究使用核心数据结合我正在建设的Web服务。我试图找到最佳的方式来存储用户信息在本地设备和post到web服务,当有一个连接。我缺乏对核心数据的了解促使我的研究,但我无法完全理解 NSIncrementalStore 的有用性。

解决方案

注意:当我在2012年写这篇文章时,如果你愿意,随时更新这个。我现在不是在任何Cocoa / ObjC项目,所以我不是一个好人,保持这个最新的,不幸的是。



核心数据提供了一组工具来帮助管理对象持久性,即保存并获取的能力



当您使用Core Data对象时,您可以使用这些对象使用从 NSPersistentStoreCoordinator 获得的 NSManagedObjectContext 执行此操作。 PSC又谈到一个或多个 NSPersistentStore 子类,它们处理存储上的实际操作。 (假设对数据库创建/读取/更新/删除)。



Core Data支持两种主要类型的存储: NSPersistentStore NSAtomicStore 。持久存储可以被认为是一个数据库:您可以增量地保存,更新和从中获取任意的记录集。原子存储是对象图的全或无表示。它旨在作为结构化文件的内存中表示。



Core Data附带的商店类型是:




  • NSSQLLiteStoreType NSPersistentStore

  • NSInMemoryStoreType NSPersistentStore

  • NSXMLStoreType NSAtomicStore )

  • NSBinaryStoreType NSAtomicStore



NSPersistentStore 明确禁止被子类化,因此,没有办法创建自己的非原子存储后端。也就是说,如果你想坚持并查询对象的表示,而不是在一个大块(加载整个图,保存整个图),你已经不幸运了。直到iOS5介绍 NSIncrementalStore



NSIncrementalStore 类(来自 NSPersistentStore ),其实现方法是在您控制的数据存储和Core Data之间提供适配器。您可以使用它封装远程API,或者如果您这样倾向,可以包装像 NULevelDB NanoStore (但我不知道为什么会这样做)。


I've been seeing NSIncrementalStore popping up as I've been researching the best ways to interact with a web service using core data.

After reading an article by Drew Crawford, a programming guide, a class reference and this tutorial a couple of times each I'm still struggling understanding what NSIncremental store is, why and when you would use it.

Could someone please explain it?

Edit
after reading mundi's answer I can see some further context is required. I'm looking into using core data in conjunction with a web service I am building. I am attempting to find the best way to store the users information locally on the device and post to web service when there is a connection. My lack of knowledge on core data prompted my research, but I was unable to fully comprehend the usefulness of NSIncrementalStore.

解决方案

NOTE: this API was bleeding-edge when I wrote this in 2012 and details have changed. Feel free to update this if you wish. I'm not working on any Cocoa/ObjC projects at the moment so I am not a good person to keep this up-to-date, unfortunately. It does seem that the overall gist is correct.

Core Data provides a set of tools that help manage object persistence, i.e. the ability to save and then fetch back sets of objects (NSManagedObject) from some kind of storage.

When you work with Core Data objects, you do so using an NSManagedObjectContext, which you get from an NSPersistentStoreCoordinator. The PSC in turn talks to one or more NSPersistentStore subclasses, which handle the actual operations on the store. (Think create/read/update/delete against a database.)

Core Data supports two primary kinds of store: NSPersistentStore and NSAtomicStore. A persistent store can be thought of as a database: you can incrementally save, update and fetch arbitrary sets of records from it. An atomic store is an 'all or none' representation of an object graph. It is intended to be an in-memory representation of a structured file.

The store types that Core Data comes with are:

  • NSSQLLiteStoreType (NSPersistentStore)
  • NSInMemoryStoreType (NSPersistentStore)
  • NSXMLStoreType (NSAtomicStore)
  • NSBinaryStoreType (NSAtomicStore)

NSPersistentStore is explicitly forbidden to be subclassed, so until now, there has been no way to create your own non-atomic store backend. That is, if you wanted to persist and query representations of your objects piecemeal as opposed to in one big lump ('load the entire graph', 'save the entire graph') you've been out of luck. Until iOS5 introduced NSIncrementalStore.

NSIncrementalStore is an abstract class (descended from NSPersistentStore) whose methods you implement to provide an adapter between a data store that you control and the world of Core Data. You can use it to wrap a remote API, or if you were so inclined you could wrap something like NULevelDB or NanoStore (though I'm not sure why you'd do that).

这篇关于NSIncrementalStore以纯英语解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆