Take the 2-minute tour ×

I've a document-based application powered by Core Data with an in-memory store. I have a table backed by an NSArrayController that is suppose to list all model objects of type Buffer. My UI also includes an NSTextView that fetches data from the the currently selected Buffer object.

I try to populate the text view thus (I'm using Fragaria):

- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
    if ([aNotification object] == editorList) {
        Buffer *buffer = [[editorListArrayController selectedObjects] objectAtIndex:0];
        [fragaria setString:[buffer valueForKey:@"content"]];

Now, whenever the user types something into the text view, I save that into the currently selected buffer and then save the changes to the managed object context:

- (void)textDidChange:(NSNotification *)notification
    [buffer setValue:[fragaria string] forKey:@"content"];
    [[self managedObjectContext] saveChanges];
    [self setEditedFlagForModelAndWindow:YES];

My problem is that when I list all the model objects in my NSArrayController they all seem to have the same value for @"content", meaning that the same value is somehow being written to all model objects. How can I debug this?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Fortunately i hade the exact same problem some time ago.

The problem is your assignment:


[fragaria string] returns a pointer to a mutable string. Every edit in your NSTextView updates the same NSMutableString object resulting in all Buffer objects being changed without Notification.

The following code works:

NSString *result = [NSString stringWithFormat:@"%@", [fragaria string]];
[buffer setValue:result forKey:@"content"];

Also [NSString stringWithString:] could be enough but I did not check this yet.

share|improve this answer
add comment

Your Answer


