• 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: Are there any NSUserDefaults keys which aren't valid?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Are there any NSUserDefaults keys which aren't valid?


  • Subject: Re: Are there any NSUserDefaults keys which aren't valid?
  • From: Jonathan del Strother <email@hidden>
  • Date: Sun, 29 Jan 2006 22:27:47 +0000

On 26 Jan 2006, at 17:57, Jonathan del Strother wrote:

I have an NSDictionary with a bunch of MP3 file dates, keyed by the artist & album of the corresponding MP3.
I'm storing this dictionary in NSUserDefaults.


For me, this works fine, but I'm seeing a bunch of crash reports from users, looking like the following :

Thread 1 Crashed:
0 com.apple.CoreFoundation 0x90740ba4 CFRetain + 60
1 com.apple.CoreFoundation 0x90751fa4 CFDictionarySetValue + 448
2 com.apple.CoreFoundation 0x9078f32c writeXMLValue + 272
3 com.apple.CoreFoundation 0x9079cd98 _CFApplicationPreferencesSet + 212
4 com.apple.Foundation 0x928f2fa0 -[NSUserDefaults setObject:forKey:] + 108




The code prompting this crash is :

NSMutableDictionary* newFileDates = [[[NSUserDefaults standardUserDefaults] objectForKey:@"File Dates"] mutableCopy];
[newFileDates setObject:fileDate forKey:albumKey];
[[NSUserDefaults standardUserDefaults] setObject:newFileDates forKey:@"File Dates"];


So, this takes the existing date structure from NSUserDefaults, adds a new NSDate to it (with a key that typically looks something like "Nirvana - Nevermind"), then saves the updated date structure back to NSUserDefaults. At this point, some people are seeing crashes.


The only potential problem I can see, is if someone has an mp3 with 'interesting' characters in the album field ("%@", for example), whether that might do something funny when it's stored in NSUserDefaults. Or, given I've managed to construct an NSString with those characters, should NSUserDefaults be able to handle anything that gets sent to it?



Another addendum - I changed the code to this :
NSMutableDictionary* newFileDates = [[[NSUserDefaults standardUserDefaults] objectForKey:@"File Dates"] mutableCopy];
[newFileDates setObject:[NSDate date] forKey:albumKey];
[[NSUserDefaults standardUserDefaults] setObject:newFileDates forKey:@"File Dates"];


- replacing NSFileManager's fileDate with just an [NSDate date]. And...it still crashes. So that rules out any oddities from NSFileManager, leaving me more & more convinced that there's something very odd going on within NSUserDefaults.

Hmm.


Jon

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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: 
 >Are there any NSUserDefaults keys which aren't valid? (From: Jonathan del Strother <email@hidden>)

  • Prev by Date: Re: NSAutoreleasePool Problem
  • Next by Date: Re: NSTreeController - setEntityName only settable once??
  • Previous by thread: Re: Are there any NSUserDefaults keys which aren't valid?
  • Next by thread: CoreData: Intermittent crash in -[NSSQLRow dealloc]
  • Index(es):
    • Date
    • Thread