Is CBLModel save async?

49 views
Skip to first unread message

Nate Smith

unread,
May 30, 2014, 4:43:19 PM5/30/14
to mobile-c...@googlegroups.com
I am calling save in my NSOutlineView's -(void)editingDidEnd:(NSNotification *)notification; method and it's causing the next outline view delegate method in the chain to fail because Item is null.  Is this because save is doing something behind the scenes that wipes out the memory address of item temporarily? 

So my edit method looks like this:

- (void)editingDidEnd:(NSNotification *)notification {
   
NSTextField *textField = [notification object];
   
SBCategory *item = [_categoryOutlineView itemAtRow:[_categoryOutlineView selectedRow]];
   
NSString* value = [textField stringValue];
    item
.title = value;
   
[item saveCategoryDocument];
}

saveCategoryDocument looks like this:

-(BOOL)saveCategoryDocument {
   
NSError* error;
   
    BOOL ok
= [self save: &error];
   
if (error) {
       
NSLog(@"Error creating categories document %@", error.localizedDescription);
   
}
   
return ok;
}


and the next delegate in line looks like this

-(BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item {
   
return [item isHeader];
}


In the above method, item is null.  If I comment out [item saveCategoryDocument]; in editingDidEnd then every thing works fine ... but it obviously doesn't save the document. 

Ragu Vijaykumar

unread,
May 31, 2014, 10:28:58 AM5/31/14
to mobile-c...@googlegroups.com
CBLModel saving is not asynchronous nor thread-safe. What is storing these items (CBLModels)? Is the storage mechanism strong or weak? Models can be dealloc'd if there are no retained pointers to them.

Nate Smith

unread,
Jun 1, 2014, 10:02:02 AM6/1/14
to mobile-c...@googlegroups.com
I have an NSArray of my model objects and it is set to (strong, nonatomic).  Just to see if it would make any difference I changed everything to strong and it didn't make a difference. 

I should mention I'm using ARC.  Also, if I put a breakpoint in it works fine.  Almost like it gives the model time to save.  It's a weird behavior and I'm exactly sure how to debug it. 

Jens Alfke

unread,
Jun 3, 2014, 1:03:18 PM6/3/14
to mobile-c...@googlegroups.com

On May 30, 2014, at 1:43 PM, Nate Smith <nates...@gmail.com> wrote:

In the above method, item is null. 

In the NSOutlineView data-source API, a nil item refers to the root of the outline. You have to special-case this, generally.

Saving a model is synchronous, and I don’t think it would affect anything to do with the outline view. Maybe the difference in timing affects what order the view renders its items in…

—Jens
Reply all
Reply to author
Forward
0 new messages