• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: saveDocument newbie question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: saveDocument newbie question


  • Subject: Re: saveDocument newbie question
  • From: mmalcolm crawford <email@hidden>
  • Date: Tue, 20 Jun 2006 18:40:42 -0700


On Jun 20, 2006, at 1:15 PM, Alan Smith wrote:

Have you printed out the arrays? You said: "But if I just edit an
existing item, both arrays remains the same..." Do you mean your code
never executes or that the items really don't ever change? If it's the
first one I suggest you use a NSEnumerator to iterate through one
array and compare it against the other. If you then get to an object
that isn't the same you can updateChangeCount. Like this:
- (void)checkArray:(id)sender
{
    NSEnumerator *enumerator = [editedArray objectEnumerator];
    id object;

while (object = [enumerator nextObject];)
{
if (! [uneditedArray containsObject: object])
{
//code to updateChangeCount
[self updateChangeCount: NSChangeDone];
break;
}
else
{
[self updateChangeCount: NSChangeCleared];
break;
}
}
[uneditedArray release];
uneditedArray = [[NSMutableArray alloc] initWithArray: editedArray];
}


No, don't do this, it's dreadful design (and setting up a timer to perform this check periodically is even worse).
There is no need at all to keep a copy of existing data simply to determine if it's changed.


Moreover, it seems likely that someone would be interested to know if the elements of an array change in addition to the array itself, and this approach does not address that need...


If you're using bindings: Neto wrote:
I have an array->arraycontroller->tableView.
I need to trigger an updateChangeCount when the array is edited.

then as a minimum implement and override the corresponding indexed accessors (see <http://developer.apple.com/documentation/Cocoa/ Conceptual/KeyValueCoding/Concepts/AccessorConventions.html#// apple_ref/doc/uid/20002174-178830-BAJEDEFB>); this will enable you add an update the change count in methods that are invoked to change the contents of the array.

For a larger-scale implementation (that addressed the issue of dirtying the document when any element is itself changed), you should either follow the pattern outlined in <http://developer.apple.com/ documentation/Cocoa/Conceptual/UndoArchitecture/index.html> or, as an earlier poster suggested, add yourself as an observer of all relevant elements of all your model objects and respond accordingly to change notifications (see "Undo" and the Graphics Bindings example at <http://homepage.mac.com/mmalc/CocoaExamples/controllers.html>).

mmalc

_______________________________________________
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


References: 
 >Excluding native file type from saveDocumentTo: accessory view. (From: Joshua Scott Emmons <email@hidden>)
 >saveDocument newbie question (From: Neto <email@hidden>)
 >Re: saveDocument newbie question (From: Andrew Merenbach <email@hidden>)
 >Re: saveDocument newbie question (From: "Alan Smith" <email@hidden>)
 >Re: saveDocument newbie question (From: Neto <email@hidden>)
 >Re: saveDocument newbie question (From: "Alan Smith" <email@hidden>)
 >Re: saveDocument newbie question (From: Neto <email@hidden>)
 >Re: saveDocument newbie question (From: "Alan Smith" <email@hidden>)

  • Prev by Date: Re: saveDocument newbie question
  • Next by Date: Sqlite Version???
  • Previous by thread: Re: saveDocument newbie question
  • Next by thread: Re: saveDocument newbie question
  • Index(es):
    • Date
    • Thread