• 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
Re: NSController's class accessing NSDocument methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSController's class accessing NSDocument methods


  • Subject: Re: NSController's class accessing NSDocument methods
  • From: BareFeet <email@hidden>
  • Date: Wed, 9 Sep 2009 18:59:29 +1000

Hi all,

Following up my previous question:

I have a MyDocument/File's Owner, NSOutlineView and bound NSTreeController in a nib file. The outline/table shows a list of Entities (nothing to do with Cocoa or CoreData) in the current document/file. I have successfully set up accessor methods for properties of Entity such as name and type. But I'm trying to set up another accessor method (dataRows) that depends on the document path. I can't see how to access the NSDocument methods from an Entity within it. How is it done?


The best solution I've come up with is to create a "document" property in each Entity as it's created, linking back to the MyDocument instance that contains it. Then each Entity can refer to the document which contains it when needed (eg when running an accessor method such as dataRows).

It makes sense to add a container reference as an extra property to an object when it's created. But I thought there might have been some built in way to do this such as in Interface Builder.

Here's the modified code:

//  Entity.h

#import <Cocoa/Cocoa.h>

@interface Entity : NSObject
{
}

@property (retain) NSString* type;
@property (retain) NSString* name;
@property (retain) MyDocument* document;
@property (retain) NSMutableArray* dataRows;

@end


// Entity.m

#import "Entity.h"
#import "MyGenerator.h"

@implementation Entity

@synthesize type;
@synthesize name;
@synthesize document;
@synthesize dataRows;

- (void) dealloc
{
	[editing release];
	[type release];
	[name release];
	[document release];
	[super dealloc];
}

- (NSMutableArray*) dataRows
{
NSString* fileString = [[[self document] fileURL] path];
NSString* selectedEntityName = [self name];
NSMutableArray* dataRowsArray = [MyGenerator dataRowsGivenFilePath:fileString entityName:selectedEntityName];
return dataRowsArray;
}


Tom
BareFeet

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NSController's class accessing NSDocument methods (From: BareFeet <email@hidden>)

  • Prev by Date: Re: KVO can be unsafe in -init?
  • Next by Date: Re: KVO can be unsafe in -init?
  • Previous by thread: NSController's class accessing NSDocument methods
  • Next by thread: Framework versioning and handling multiple OS SDK's?
  • Index(es):
    • Date
    • Thread