Core Data: undo and non-object attribute
Core Data: undo and non-object attribute
- Subject: Core Data: undo and non-object attribute
- From: Matteo Rossi <email@hidden>
- Date: Sat, 14 Oct 2006 20:53:44 +0200
I'm surely missing a fundamental piece but I can't find it.Here's my
problem. I'm writing a drawing app and I want to implement an ivar in
my graphic object like this:
typedef struct __XSAPPoint
{
double x;
double y;
} XSAPPoint;
@interface mybasic : NSManagedObject
{
XSAPPoint _point;
}
I'm using CD to manage save/undo and object graph operations. In my
entity I declared four attributes: x and y as transient undefined and
xValue, yValue as double optional persistent.
Here's the code I wrote:
@implementation mybasic
- (void)awakeFromFetch
{
NSNumber *value;
[super awakeFromFetch];
value = [self valueForKey:@"xValue"];
if (value != nil )
_point.x=[value doubleValue];
value = [self valueForKey:@"yValue"];
if (value != nil )
_point.y=[value doubleValue];
}
- (double)x
{
[self willAccessValueForKey: @"x"];
double tmpValue = _point.x;
[self didAccessValueForKey: @"x"];
return tmpValue;
}
- (void)setX:(double)value
{
[self willChangeValueForKey: @"x"];
_point.x=value;
[self didChangeValueForKey: @"x"];
}
- (double)y
{
[self willAccessValueForKey: @"y"];
double tmpValue = _point.y;
[self didAccessValueForKey: @"y"];
return tmpValue;
}
- (void)setY:(double)value
{
[self willChangeValueForKey: @"y"];
_point.y=value;
[self didChangeValueForKey: @"y"];
}
- (void)willSave
{
[self setPrimitiveValue:[NSNumber numberWithDouble:_point.x]
forKey:@"xValue"];
[self setPrimitiveValue:[NSNumber numberWithDouble:_point.y]
forKey:@"yValue"];
[super willSave];
}
@end
Then I created a simple interface by option-dragging my entity in my
doc window in IB.I can save and undo/redo insert/delete operations
but I can't undo a value editing. The undo is available after an edit
but the value stays the same. What's wrong with my code ?
Thank you
Matteo Rossi
_______________________________________________
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