• 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
Core Data And Required Bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Core Data And Required Bindings


  • Subject: Core Data And Required Bindings
  • From: Chris Outwin <email@hidden>
  • Date: Sat, 18 Nov 2006 17:13:50 -0600

Because I'm still new at Core Data, I'm not sure if the problem I'm experiencing is a limitation of Core Data or my current skills.

I have a very simple test app which draws rectangles in a separate window. The app has one entity called MyRect. MyRect contains just 4 attributes: drOriginX, drOriginY, drHeight, and drWidth. These are of type float.

The entity has a custom class called MyRect which contains two methods:

+ (void)initialize {
if (self == [MyRect class]) {
NSArray* keys = [NSArray arrayWithObjects:@"drOriginX", @"drOriginY", @"drWidth", @"drHeight", nil];
[self setKeys:keys triggerChangeNotificationsForDependentKey:@"bounds"];
}
}


- (NSString *)bounds {
	NSRect rect = NSMakeRect([[self valueForKey:@"drOriginX"] floatValue],
							 [[self valueForKey:@"drOriginY"] floatValue],
							 [[self valueForKey:@"drWidth"] floatValue],
							 [[self valueForKey:@"drHeight"] floatValue]);

	NSString* rectAsString = NSStringFromRect(rect);

	[view setNeedsDisplay:YES];

	return rectAsString;
}

The Problem
Everything works fine as long as I include a NSTextField in the UI which is bound to bounds. However, there's no need to display bounds as a string.
When I unbind bounds, the bounds method is no longer called when I change one of the attributes. The docs say NSManagedObject turns automatic KVO off for attributes in the model, so I can't observe the attributes.


My WorkAround
This forces me to include methods in the MyRect custom class to monitor attribute changes such as:


- (void)setDrOriginX:(NSNumber *)newOriginX {
	[self willChangeValueForKey:@"drOriginX"];
	[self setPrimitiveValue:newOriginX forKey:@"drOriginX"];
	[self didChangeValueForKey:@"drOriginX"];

	[view setNeedsDisplay:YES];
}

What should I do to have the bounds method called when an attribute is changed in the UI? Am I stuck with including - (void)setDrOriginX: (NSNumber *)newOriginX?

Thank you for your help.


_______________________________________________
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
  • Follow-Ups:
    • Re: Core Data And Required Bindings
      • From: mmalc crawford <email@hidden>
    • Re: Core Data And Required Bindings
      • From: mmalc crawford <email@hidden>
    • Re: Core Data And Required Bindings
      • From: Scott Stevenson <email@hidden>
  • Prev by Date: Re: Re: Non-square (triangular) views
  • Next by Date: Re: Non-square (triangular) views
  • Previous by thread: Re: Importing CICN resources from file
  • Next by thread: Re: Core Data And Required Bindings
  • Index(es):
    • Date
    • Thread