• 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: Managed Object Context Reference
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Managed Object Context Reference


  • Subject: Re: Managed Object Context Reference
  • From: Joanna Carter <email@hidden>
  • Date: Tue, 1 Jun 2010 09:37:41 +0100

Le 1 juin 2010 à 06:53, Quincey Morris a écrit :

> You've created another scenario by making your view need the managed object context (probably during 'drawRect:' at least?).…

Richard, this really points to an "abuse" of the MVC design pattern :-)

If you look at some of the Cocoa controls, like NSTableView for example, you will see that there is also an NSTableViewDelegate protocol, with methods like -tableView:willDisplayCell:forTableColumn:row:, which have to be implemented, usually, in a Controller class.

This ensures separation between the View and the Model it is meant to be representing. Using a delegate to obtain the data required for drawing a View means that the view has no need to know anything about the Model, the MOC or anything else, apart from the fact that something, somewhere, will supply the necessary information in response to a request via the delegate methods.

So, for something simple like a CircleView, should also require a protocol like this:

@protocol CircleViewDelegate

- (void) circleView:(CircleView *)circleView willDisplayCircle:(Circle **)circle;

@end

This then is called from within the CircleView like this:

- (void) someMethod; // in CircleView that needs the Circle coordinates
{
 Circle *circle = nil;

 [delegate circleView:self willDisplayCircle:&circle];

 // draw circle using circle.location and circle.radius.
}

Then the delegate method, in the Controller:

- (void) circleView:(CircleView *)circleView willDisplayCircle:(Circle **)circle
{
 NSPoint circleLocation = … get location from object in MOC

 CGFloat circleradius = … get radius from object in MOC

 circle = [Circle circleAtLocation:circleLocation withRadiusOf:circleRadius];
}

Of course, this is a very simplistic (and not very well written) example, but you should get the idea that any code that talks to the MOC can be located in the Controller and accessed from the View via a delegate.

Joanna

--
Joanna Carter
Carter Consulting
--
Joanna Carter
Carter Consulting

_______________________________________________

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

  • Follow-Ups:
    • Re: Managed Object Context Reference
      • From: Richard Somers <email@hidden>
  • Next by Date: Re: dynamic resolution
  • Next by thread: Re: Managed Object Context Reference
  • Index(es):
    • Date
    • Thread