• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
CoreData - KVO on unarchived array/dictionary elements?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CoreData - KVO on unarchived array/dictionary elements?


  • Subject: CoreData - KVO on unarchived array/dictionary elements?
  • From: Terrence Talbot <email@hidden>
  • Date: Mon, 10 Oct 2005 14:11:07 -0700


Another issue that recently surfaced relates to getting notifications for changes to structures stored in CoreData but archived/unarchived as NSData. I'm hoping someone here might be able to suggest a path to take to fix this.


The explanation's a little long: To allow plugins for an app to be extensible and store whatever data they wish, I have an Entity/Class called StoredDictionary which writes key/value pairs to a keyvalues table. (Actually, I have an optimization that looks at the values and stores NSStrings in a KeyValueAsString table while taking other "Foundation" structures and using NSPropertyListSerialization to store them in a KeyValueAsData table.) This all works fine. I also have a StoredArray Entity/Class that does the same for NSArray- and NSSet-like objects. The portion of the model that lays this out looks like this: http://www.talblog.info/images/coredata-kvo.png

I originally got this idea from wanting to have the same (high-level) mechanism in Core Data that DataCrux had for storing key/value pairs. I had it confirmed, I thought, at WWDC that something like this was the recommended way to deal with storing NSDictionary-like things. So far so good.

Here's the issue:

Say I have an object that has a reference to a StoredDictionary called pluginPropeties. Say further that one of the entries in the dictionary is an array called linkList. linkList itself is a regular NSArray of NSDictionarys containing various information about different links (title, URL, etc.). In the main this works fine, unless I use bindings.

The issue appears to be that when linkList comes out of cold storage, by essentially doing [NSPropertyListSerialization propertyListFromData:], and gets vended back to the other side of the binding, changing any of the items in linkList (or any of the entries in one of the dictionaries held by linkList) is never noticed by pluginProperties so the changes to the data are not put back in the datastore. (pluginProperties never gets setValue:forKey: when something is changed inside linkList)

I think I can solve the case for pluginProperties storing NSDictionarys by sending addObserver:forKeyPath: to the unarchived dictionary for every key in the dictionary. Tedious, but doable. Does that seem a rational approach?

But I don't see a way to do that for NSArrays. I see that there is an addObserver:toObjectsAtIndexes:forKeyPath: method where I could pass in an index range of the entire array, but I don't understand what to pass in for keyPath. Arrays don't generally have keys.

Am I missing something obvious? Is there a better approach?

Thanks much,


Terrence

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: CoreData - KVO on unarchived array/dictionary elements?
      • From: Terrence Talbot <email@hidden>
  • Prev by Date: Re: Newbie-Saving file in Tiger
  • Next by Date: Re: Newbie-Saving file in Tiger
  • Previous by thread: [Meet] Cocoaheads Los Angeles organizational meeting
  • Next by thread: Re: CoreData - KVO on unarchived array/dictionary elements?
  • Index(es):
    • Date
    • Thread