• 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: Accessing objects two ways in an object hierarchy
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessing objects two ways in an object hierarchy


  • Subject: Re: Accessing objects two ways in an object hierarchy
  • From: Graham Cox <email@hidden>
  • Date: Tue, 6 Jan 2009 21:01:53 +1100


On 5 Jan 2009, at 7:15 pm, Per Ohlson wrote:

I have a relationship similar to the following model in my program:

http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/Art/object_graph.gif

To access the objects corresponding to the collection of "employees" from the "department", I just iterate through the collection and fetch the object.
But what is the best way to access the "department" from an "employee"?


There's no reason not to use a back-pointer. Just don't create a retain cycle. In other words, decide who owns what - in this case, 'department' would own 'employees' I guess - so the reference back to department would be weak, i.e. unretained.

I typically set back-pointers when objects are added to collections, so I'd have a department method:

- (void)	addEmployee:(Employee*) emp
{
	[mEmployeesArray addObject:emp];
	[emp setDepartment:self];
}


and an employee method:

- (void)	seDepartment:(Department*) dept
{
	mDeptRef = dept;
}

hth,

Graham


_______________________________________________

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: 
 >Accessing objects two ways in an object hierarchy (From: Per Ohlson <email@hidden>)

  • Prev by Date: Re: Overlay controls a la iTunes and QuickTime
  • Next by Date: Re: Test
  • Previous by thread: Accessing objects two ways in an object hierarchy
  • Next by thread: Enum advice please (resend not sure if it was delivered ?)
  • Index(es):
    • Date
    • Thread