• 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: NSUserDefaults locks up on 10.8
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSUserDefaults locks up on 10.8


  • Subject: Re: NSUserDefaults locks up on 10.8
  • From: Quincey Morris <email@hidden>
  • Date: Thu, 09 Aug 2012 23:15:21 -0700

On Aug 9, 2012, at 22:49 , Martin Hewitson <email@hidden> 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.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Prev by Date: Re: 32-bit on 10.8
  • Next by Date: Re: Not getting all the data over the cell network
  • Previous by thread: Re: Navigating in a NSTableView with tab key
  • Next by thread: Missing creating date for items copied with copyItemAtPath:toPath:error:?
  • Index(es):
    • Date
    • Thread