• 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: Core Data and ordered relationships
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data and ordered relationships


  • Subject: Re: Core Data and ordered relationships
  • From: "Sean McBride" <email@hidden>
  • Date: Tue, 16 Sep 2008 18:29:02 -0400
  • Organization: Rogue Research

On 9/15/08 3:13 PM, Jamie Hardt said:

>> b) add an attribute named 'index' (value 1 to 6) and code methods
>> named
>> employee1, etc. in my NSManagedObject subclass?
>
>Certainly do the second one, unless there's some factor in your
>business logic that demands exactly six employees, but I can't imagine
>a situation where doing the to-many would be less good.  First rule of
>database normalization: never have repeating fields, and any time you
>have an ordinal in a column name that's exactly what you're doing.
>
>In order for these employees to always appear in the same order, you
>display them in a NSTableView bound to an NSArrayController with a
>sort descriptor set on your "index" key.  Also, take a look at this on
>how you can implement drag-and-drop reordring on your array
>controllers, as well...
>
>http://hmdt.jp/archives/image/2005_11/DNDCoreData.pdf
>
>This might remove the need for you to have messy -employee[1-6]
>methods on your Department object.

Hi Jamie,

Thanks for your reply.  Well, of course, I'm not actually dealing with
Employees and Departments, but to continue the analogy...

Let's say I actually have a complex custom NSView that draws a 3D
rendering of a human.  This view in not aware of the Employee datatype.
This view supports bindings, and exposes several.  My nib has 6 of these
views.  I have an NSObjectController that matches some Department, call
it departmentController.  view1 binds to departmentController's
selection.employee1.armLength and selection.employee1.headRadius, etc.
view2 binds similarly but with employee2 in the keypath, etc.

How to implement Department's employee1 method?  Would this be correct:

- (Employee*)employee1
{
	[self willAccessValueForKey:@"employee1"];

	Employee* employee = nil;

	NSSet* theEmployees = [self employees];
	for (Employee* anEmployee in theEmployees)
	{
		if ([anEmployee position] == 1)
		{
			employee = anEmployee;
			break;
		}
	}

	[self didAccessValueForKey:@"employee1"];

 return employee;
}

It seems to mostly work, except for situations involving faults firing,
in which case I get an exception about mutating while iterating.

Cheers,

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada


_______________________________________________

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: 
 >Core Data and ordered relationships (From: "Sean McBride" <email@hidden>)
 >Re: Core Data and ordered relationships (From: Jamie Hardt <email@hidden>)

  • Prev by Date: Re: referencing XML Data
  • Next by Date: Swapping IB-created views and keeping IBOutlets hooked up
  • Previous by thread: Re: Core Data and ordered relationships
  • Next by thread: MySQL?
  • Index(es):
    • Date
    • Thread