Smart Containers

Stefan Urbanek stefan at agentfarms.net
Mon Feb 5 15:30:51 PST 2007


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





More information about the MacOSX-dev mailing list