Core Data and two linked NSOutlineView (s) - ala Safari bookmarks
Core Data and two linked NSOutlineView (s) - ala Safari bookmarks
- Subject: Core Data and two linked NSOutlineView (s) - ala Safari bookmarks
- From: Nicholas Crosbie <email@hidden>
- Date: Mon, 5 Sep 2005 18:03:44 +1000 (EST)
Hi all,
I'm trying to set up a document-based core data app.
with 2 entities, where each entity describes a tree
controlled by its own NSTreeController. The
ultimate aim is to have the 'first' tree set the focus
for the 'second' tree (ala Safari bookmarks GUI).
Using the OutlineEdit example (/Developer/Examples/
CoreData) as a starting point, I set up my 2 entities
(called 'Group' and 'Sample'), and alter the NIB file
to contain 2 NSOutlineView (s).
I connect and bind in IB, then build, but get
'undeclared' errors for the 'Sample' entity.
i.e. WHEREAS THIS IS FINE
************************************************
- (IBAction) dedentGroup: sender;
{
/* The controller's -selection method will return
a proxy to the object or objects that are actually
selected.
*/
id selection = [groupsTreeController selection];
Group *parent = [selection
valueForKeyPath:@"parent"];
// make sure exactly one object is selected.
if (parent == nil || parent == NSMultipleValuesMarker
|| parent == NSNoSelectionMarker || parent ==
NSNotApplicableMarker) {
NSBeep();
return;
}
parent = [parent valueForKeyPath:@"parent"];
[selection setValue:parent forKeyPath:@"parent"];
}
************************************************
THIS GIVES 'Sample' UNDECLARED ERROR
- (IBAction) dedentSample: sender;
{
/* The controller's -selection method will return
a proxy to the object or objects that are actually
selected.
*/
id selection = [samplesTreeController selection];
Sample *parent = [selection
valueForKeyPath:@"parent"];
// make sure exactly one object is selected.
if (parent == nil || parent == NSMultipleValuesMarker
|| parent == NSNoSelectionMarker || parent ==
NSNotApplicableMarker) {
NSBeep();
return;
}
***************************************************
The 'Group' entity is just a rename of the 'Note'
entity from the original OutlineEdit app. The
'Sample' entity is also set up
like the original 'Note' entity, and has it's own
'contents' attribute and 'parent' and 'children'
relationships, and its own
interface and implementation files (Sample.h,
Sample.m) since it is modeled as a subclass of
NSManagedObject (ala the 'note'
entity from the original OutlineEdit app).
In MyDocument.m, I create a single 'sample' in the
same way as a single 'group'.
i.e.
********************************************************************
- (id)initWithType:(NSString *)typeName error:(NSError
**)outError;
{
// this method is invoked exactly once per
document at the initial creation
// of the document. It will not be invoked when a
document is opened after
// being saved to disk.
self = [super initWithType:typeName
error:outError];
if (self == nil)
return nil;
NSManagedObjectContext *managedObjectContext =
[self managedObjectContext];
// create a single group
[NSEntityDescription
insertNewObjectForEntityForName: @"Group"
inManagedObjectContext: managedObjectContext];
// create a single sample
[NSEntityDescription
insertNewObjectForEntityForName: @"Sample"
inManagedObjectContext: managedObjectContext];
// clear the undo manager and change count for the
document such that
// untitled documents start with zero unsaved
changes
[managedObjectContext processPendingChanges];
[[managedObjectContext undoManager]
removeAllActions];
[self updateChangeCount:NSChangeCleared];
return self;
}
****************************************************************
I can't figure out why Sample is flagged undeclared
but Group isn't. All the code and IB elements for
Sample have been setup as in Group.
Also, is my approach the best way to go about creating
a (Safari-like) 'linked-tree' app that uses Core Data
and is document-based? Please expect a delay in my
responses to posts. This is coming from the Southern
Hem.
thanks in advance,
Nick
____________________________________________________
Do you Yahoo!?
The New Yahoo! Movies: Check out the Latest Trailers, Premiere Photos and full Actor Database.
http://au.movies.yahoo.com
_______________________________________________
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