Hi Quincey, Your suggested fix works fine, except I used -arrayForKey rather than -arrayValueForKey (which I couldn't find). Thanks for the explanation!
Cheers, Martin On Aug 10, 2012, at 07:15 AM, Quincey Morris <quinceymor...@rivergatesoftware.com> wrote: > On Aug 9, 2012, at 22:49 , Martin Hewitson <martin.hewit...@aei.mpg.de> wrote: > >> I have a table view bound to shared user defaults with a key which returns >> an array of strings. >> I have a button for creating a new entry. This calls a piece of code like >> this: >> >> >> NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; >> NSMutableArray *commands = [defaults >> mutableArrayValueForKey:TECiteCommands]; >> [commands addObject:newCommand]; >> [defaults setObject:commands forKey:TECiteCommands]; >> [defaults synchronize]; >> [commandsTable reloadData]; > >> I guess I'm abusing the use of NSUserDefaults somehow, but I don't know how. > > > I've seen an array operation hang before, when 'mutableArrayValueForKey:' is > not being used properly. > > It's improper because NSUserDefaults isn't MVC-compliant this for kind of > change. A setting that's an array object (in spite of the convenience > accessor 'arrayValueForKey:') isn't represented by an array property at all. > (It is represented, I would imagine, by a NSData object that consists of the > results of archiving the array object you originally specified.) > > You should probably do something like this instead: > >> NSMutableArray *commands = [[defaults arrayValueForKey:TECiteCommands] >> mutableCopy]; // because arrayValueForKey returns an immutable object >> [commands addObject:newCommand]; >> [defaults setObject:commands forKey:TECiteCommands]; > > My guess is that it only ever worked because of an accidental implementation > detail. > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Martin Hewitson Albert-Einstein-Institut Max-Planck-Institut fuer Gravitationsphysik und Universitaet Hannover Callinstr. 38, 30167 Hannover, Germany Tel: +49-511-762-17121, Fax: +49-511-762-5861 E-Mail: martin.hewit...@aei.mpg.de WWW: http://www.aei.mpg.de/~hewitson ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com