Core Data: Progress bar using Sheet, modifying context in thread
Core Data: Progress bar using Sheet, modifying context in thread
- Subject: Core Data: Progress bar using Sheet, modifying context in thread
- From: Bill Coleman <email@hidden>
- Date: Fri, 4 Aug 2006 00:05:51 -0400
Hi. I'm relatively new to Cocoa. Although I've dabbled with it for
five years, this summer is the first time I've gotten serious with
it. I've found it to be a powerful and relatively complete framework,
and that often if something is hard to do, I must be doing it wrong.
Writing the application is easy. Figuring out how to do it is hard.
I have a relatively simple application that keeps a single list of
rows using Core Data, and displays the list in an NSTableView. I've
written an import / export operation to move data from and to this
list via a different text format.
Question 1: I'd like the import or export process to be document-
modal, with the progress of the operation displayed in a sheet. This
is a little tricky, since once you call beginSheet:
modalForWindow: ..., you can't do any more processing. So, to perform
the actual operation, I first start an NSThread. Getting it to quit
properly was tricky, as you have to use performSelectorOnMainThread:
to get the endSheet: call to work.
My question is -- is this the right way to do this? Is there a better
way? It seems to be fraught with problems.
Question 2: Export seems to work ok. Import, however, acts a bit
funny. I create new rows for import by calling [NSEntityDescription
insertNewObjectForEntityForName:inManagedObjectContext:]. I add the
object to the NSArrayController by calling addObject:. The addObject:
message, however, doesn't seem to be necessary for reasons I don't
fully understand.
What I'm seeing is that the objects end up showing up in the
NSTableView as each one is imported. This didn't happen before I
added the sheet and thread. It appears that the table is observing
the insertions and trying to update -- which really slows down the
import process.
My question is -- is there any way I can turn off this update of the
NSTableView until I'm done? Can I create instances of managed objects
and then add them to the managed context all at once?
Question 3: During a long import, the update of the NSTableView often
stops after a number of rows are inserted. (It appears to always be
powers of 2 -1, eg 63, 255) Sometimes, I get bad access exceptions
during this update process. This makes me thing I'm doing something
wrong in this multi-threaded environment.
My progress bar also seems to jump back and forth a bit, even though
I'm steadily increasing the value passed to setDoubleValue:, and I
don't change the maximum value after the import starts.
Anyone have insight into this? I've been reading Cocoa docs for the
last couple of days.
Appreciate any thoughts.
Bill Coleman, AA4LR, PP-ASEL Mail: email@hidden
Quote: "We invented personal computing."
-- Bill Gates @ TechNet / MSDN 2003
_______________________________________________
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