Smart Containers

Stefan Urbanek stefan at agentfarms.net
Mon Feb 5 23:38:28 PST 2007


Excuse me for not giving enough facts.

Goal is to have ordinary folders (manual folders), smart folders and built-in
smart folders. Problems are causing the built-in smart folders, like 'Library'
in CoreRecipes or iTunes. For simplicity, let us have only one built-in smart
folder called Universe holding all objects - having 'true predicate'.

The built-in folders are created by the application, but are not stored in the
document store. The CoreRecipes solves this problem by having two stores:
in-memory store and default on-disk store. The Universe object is created and
put in the memory store, other objects are created and assigned to the default
store. Because the core recipes is not document based it uses only one default
store and the store has permanent location within user's directory structure -
the URL of that store is known from the beginning.

My application is a document based application. When I create a new document, I
do not know where default document store is located, as it does not exist,
obviously. However, I need to put new objects somewhere. I can not put them
into the memory store where built-in smart folders are, as I do not want to mix
them. I want to keep built-in smart folders separate. Therefore I need to create
temporary in-memory store which I call 'unsaved document store'. This is the
default document store from the beginning until user saves the document.

When user saves the document for the first time, the unsaved document store is
migrated from memory to the user specified URL. At this point I have two
persistant stores: in-memory store for built-in smart folders and on-disk store
as the default document store. (I am using three instance variables to know the
state of my stores. I can use a flag instead...) If user opens an existing
document, then the unsaved document store is not created at all.

Stefan Urbanek

Citát Christiaan Hofman <cmhofman at gmail.com>:

> I am totally confused about your store setup. Do you have 3 persistent
> store, and why would you want that? Usually you have one persistent store
> for each URL. You have at least 2 (the default one, and the documentStore
> you added, I don't know what unsavedDocumentStore is). There might be a
> problem that some group is on one persistent store, while the containing
> objects it refers to is in another.
> 
> Christiaan
> 
> On 2/6/07, Stefan Urbanek <stefan at agentfarms.net> wrote:
> >
> >
> > On 15.1.2007, at 17:16, Christiaan Hofman wrote:
> >
> > > I suggest you try to work through the CoreRecipes example project(s),
> > > it contains smart groups and a UI to create predicates for smart
> > > groups (be careful because it contains some bugs, at least the last
> > > time I looked at it.)  It's fairly complex, but that's just the way
> > > it is (though I think their UI controller is a bit too complicated.)
> > > This should give you an idea of the concepts involved in building
> > > smart groups. If you have questions about specific (implementation)
> > > details, you can come back to this list with those.
> > >
> >
> > Thank you for your suggestion. I am now following the CoreRecipes
> > example, with small modifications - I use NSPersistentDocument. I
> > will try to create a short how-to to this problem after finishing it :-)
> >
> > The basic model is similar to the CoreRecipes:
> >
> > Group -> Context
> > SmartGroup -> AbstractContext (i will use 'smart folder' name here)
> > ManualGroup -> ConcreteContext (i will use 'folder' name here)
> > Recipe -> Object
> >
> > initialisation of document:
> > - set up a persistent store for 'smart folder'
> > - set up smart folder called Universe and assign it to the 'smart' store
> > - create 'unsaved document store'
> >
> > in configurePersistentStoreCoordinatorForURL I do:
> >
> >      if unsavedDocumentStore != nil
> >
> >          documentStore = [coordinator
> > migratePersistentStore:unsavedDocumentStore
> >                                                        toURL:url
> >                                                      options:nil
> >
> > withType:NSXMLStoreType
> >                                                        error:error];
> >
> >      else
> >
> >          documentStore = [coordinator
> > addPersistentStoreWithType:NSXMLStoreType
> >                                                    configuration:nil
> >                                                              URL:url
> >                                                          options:nil
> >                                                            error:error];
> >
> > I have special action method for creating new concrete folder,
> > similar to one in CoreRecipes. This is to make sure that the new
> > folder is placed to the document persistent store. Also to prevent
> > array controller to create instance of an abstract class.
> >
> > The UI is quickly designed as follows:
> > - table view for folders
> > - table view for objects
> > - some text fields for selected object
> > - array controller for folders
> > - array controller for objects
> >
> > Folder creation works, object creation works as well. The 'Universe'
> > folder works as expected. When I save the document without objects,
> > only with new folders, it works. When I create some objects and try
> > to save the document I get:
> >
> > 2007-02-06 00:10:55.048 SocNet6[6838] *** -[NSCFArray
> > subarrayWithRange:]: index (2) beyond bounds (2)
> >
> > Stack:
> >
> > #0      0x9297c008 in -[NSException raise]
> > #1      0x9297be5c in +[NSException raise:format:]
> > #2      0x92985248 in -[NSArray subarrayWithRange:]
> > #3      0x940ceb08 in -[NSPersistentStoreCoordinator(_NSInternalMethods)
> > executeRequest:withContext:]
> > #4      0x940e1b68 in -[NSManagedObjectContext save:]
> > #5      0x93c39ee4 in -[NSPersistentDocument
> > writeToURL:ofType:forSaveOperation:originalContentsURL:error:]
> > #6      0x93953458 in -[NSDocument
> > _writeToURL:ofType:forSaveOperation:inFolder:makingTemporaryCopyInFolder
> > :error:]
> > #7      0x93952f6c in -[NSDocument
> > _writeSafelyToURL:ofType:forSaveOperation:error:]
> > #8      0x93952cc8 in -[NSDocument
> > writeSafelyToURL:ofType:forSaveOperation:error:]
> > #9      0x93c3a1fc in -[NSPersistentDocument
> > writeSafelyToURL:ofType:forSaveOperation:error:]
> > #10     0x93952a08 in -[NSDocument
> > saveToURL:ofType:forSaveOperation:error:]
> > #11     0x93a3fce8 in -[NSDocument
> > _saveToURL:ofType:forSaveOperation:delegate:didSaveSelector:contextInfo:
> > ]
> > #12     0x93952944 in -[NSDocument
> > saveToURL:ofType:forSaveOperation:delegate:didSaveSelector:contextInfo:]
> > #13     0x939526c4 in -[NSDocument
> > saveDocumentWithDelegate:didSaveSelector:contextInfo:]
> > #14     0x937acc4c in -[NSApplication sendAction:to:from:]
> > ...
> >
> > I do not know what the array is. The number 2 does not reflect
> > anything known to me - neither number of objects, nor number of
> > folders. Only known 2 is number of persistent stores.
> >
> > Does anyone know what is possibly causing the problem? What should I
> > try to get more information about what is going on?
> >
> > Thanks for any hints,
> >
> > <rest snipped>
> >
> > Stefan Urbanek
> > --
> > http://stefan.agentfarms.net
> >
> > First they ignore you, then they laugh at you, then they fight you,
> > then you win.
> > - Mahatma Gandhi
> >
> >
> >
> >
> _______________________________________________
> MacOSX-dev mailing list
> MacOSX-dev at omnigroup.com
> http://www.omnigroup.com/mailman/listinfo/macosx-dev
> 
> 


-- 
http://stefan.agentfarms.net

First they ignore you, then they laugh at you, then they fight you,
then you win.
- Mahatma Gandhi


More information about the MacOSX-dev mailing list