[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Design issue for MVC and database updates
If you are going to do database access using Cocoa, please study EOF
first. EOF was designed as a database access framework, but much of its
technology is now in Cocoa, including key value coding, NSUndoManager,
and now NSController.
In fact, this is exactly how EOF tracks object changes and saves them
to the database. EOEditingContext registers for change notifications
from its EOs and puts them on its changedObjects list.
-Kenny
On Mar 2, 2004, at 3:55 PM, Scott Stevenson wrote:
>
> On Mar 2, 2004, at 3:03 PM, Joakim Danielson wrote:
>
>> Well the problem is not in the database methods really but more what
>> I must implement to see which object's how has changed. But I supply
>> the method anyway:
>>
>> - (IBAction)saveToDb:(id)sender
>
> Your best bet is probably key-value observing (Panther only):
> http://developer.apple.com/documentation/Cocoa/Conceptual/
> KeyValueObserving/
>
> You can observe each item, and whenever the a value changes in the
> object, you can add them item to a "changedObjects" mutable array.
> This is probably best done outside of the NSArrayController.
>
>
> Then, you change your database saving action method to this:
>
> - (IBAction)saveToDb:(id)sender {
>
> NSEnumerator *iterator;
> JDTransactionType *item;
> int newId;
>
> // get the list of changed objects
> NSMutableArray * changedObjects = [self changedObjects];
> iterator = [changedObjects objectEnumerator];
>
> ....
>
> // after you're done, empty the array
> [objectsToUpdate removeAllObjects];
> }
>
>
> I haven't yet found a way to ask NSArrayController which object it
> just edited (although it seems like a something a lot of people would
> use). But if someone else has, that would negate the need to observe
> each object separately.
>
> I guess it would be pretty easy to override -objectDidBeginEditing to
> check -selection and add it to an array, or something of that nature.
> Not sure if it's reasonable to assume the selection is the one being
> edited.
>
> - Scott
>
> --
> Tree House Ideas
> http://treehouseideas.com/
>
> _______________________________________________
> MacOSX-dev mailing list
> MacOSX-dev@xxxxxxxxxxxxx
> http://www.omnigroup.com/mailman/listinfo/macosx-dev
>