Core Data: Updating MOC doesn't make document dirty when using NSTextField

  • Hello,

    I have a  couple NSTextField's that are bound to a model objects
    attributes ( first name, last name etc.). When I modify the values in
    these text fields the document is not becoming dirty. However as soon
    as I go to the Edit menu the document becomes dirty. I believe the
    reason why it makes the document dirty is after you go to the edit
    menu  it seems to validate the Redo menu item which checks for any
    changes in the MOC and registers an undo grouping via -
    [NSManagedObjectContext _registerUndoForModifiedObjects:]. So my
    question is why is it not grouping an undo around the setting the new
    value in the MOC. My Accessor methods look like the following:

    In my Person class (which is a subclass of _Person)
    - (void)setFirstName:(NSString *)value
    {
        [super setFirstName:value];
        [self setName:[NSString stringWithFormat:@"%@ %@", [self
    firstName], [self lastName]]];
        [self setHasBeenModified:YES];
    }

    In my _Person class (subclass of NSManagedObject)

    - (void)setFirstName:(NSString *)value
    {
    [self willChangeValueForKey:@"firstName:];
    [self setPrimitiveValue:value forKey:@"firstName"];
    [self setUpdatedByAndDate];
    [self didChangeValueForKeY:@"firstName"];
    }

    A few other interesting things:

    1.) Using an NSTextView does not have this problem.
    2.) Putting a beginUndoGrouping around the accessor methods such as -
    (void)setFirstName:(NSString *)value fixes the problem.

    Thanks,
    Matthew Smith
  • I was able to track this problem down to some other trickery I was
    doing when creating the document, please disregard this problem.

    Thanks,
    Matthew Smith

    On Oct 31, 2006, at 10/31/06  2:34 PM, Matt Smith wrote:

    > Hello,
    >
    > I have a  couple NSTextField's that are bound to a model objects
    > attributes ( first name, last name etc.). When I modify the values
    > in these text fields the document is not becoming dirty. However as
    > soon as I go to the Edit menu the document becomes dirty. I believe
    > the reason why it makes the document dirty is after you go to the
    > edit menu  it seems to validate the Redo menu item which checks for
    > any changes in the MOC and registers an undo grouping via -
    > [NSManagedObjectContext _registerUndoForModifiedObjects:]. So my
    > question is why is it not grouping an undo around the setting the
    > new value in the MOC. My Accessor methods look like the following:
    >
    > In my Person class (which is a subclass of _Person)
    > - (void)setFirstName:(NSString *)value
    > {
    > [super setFirstName:value];
    > [self setName:[NSString stringWithFormat:@"%@ %@", [self
    > firstName], [self lastName]]];
    > [self setHasBeenModified:YES];
    > }
    >
    > In my _Person class (subclass of NSManagedObject)
    >
    > - (void)setFirstName:(NSString *)value
    > {
    > [self willChangeValueForKey:@"firstName:];
    > [self setPrimitiveValue:value forKey:@"firstName"];
    > [self setUpdatedByAndDate];
    > [self didChangeValueForKeY:@"firstName"];
    > }
    >
    > A few other interesting things:
    >
    > 1.) Using an NSTextView does not have this problem.
    > 2.) Putting a beginUndoGrouping around the accessor methods such as
    > -(void)setFirstName:(NSString *)value fixes the problem.
    >
    > Thanks,
    > Matthew Smith
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/<msmith...>
    >
    > This email sent to <msmith...>
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today