Re: NSDictionary crash
Re: NSDictionary crash
On Sat, Jul 25, 2009 at 8:20 PM, Kyle Sluder<email@hidden> wrote:
> On Jul 25, 2009, at 11:00 AM, "email@hidden"
> <email@hidden> wrote:
>
>> I find the third option the most likely: iTunes rewrites the data file
>> frequently. Is there a way to lock the file while reading it, or
>> detect if it is being modified, or suchlike? Thanks.
>
> You aren't guaranteed that the iTunes library file will always be a plist.
You mean because it might be rewritten or corrupted while my app is
reading it, or because the format might change in the future?
> The "correct" recommendation, which will also solve your issue, is to use
> Apple Events to get the information you need.
Yes, but then iTunes would have to be running. Plus it's a lot slower.
I believe the sole purpose of the xml file (as opposed to the actual
iTunes library file) is for third parties to be able to access iTunes
data without querying iTunes.app.
> In the general case, since you didn't write -[NSDictionary
> initWithContentsOfFile:], you can't make it safe. You'll have to open the
> file and read it's data yourself, then hand that off to the NSDictionary
> initializer (or perhaps NSPropertyListSerialization).
If I get the data with e g NSData's initWithContentsOfFile:, how would
I initialize the dictionary? I don't see any dictionaryWithData: or
suchlike in NSDictionary. Would I have to do the parsing myself?
Also, is the NSData equivalent any safer than NSDictionary's? It's
initWithContentsOfFile: method is documented to return "An initialized
object—which might be different than the original receiver—that
contains the dictionary at path, or nil if there is a file error or if
the contents of the file are an invalid representation of a
dictionary." There's no mention of a potential crash. Should I file a
bug?
I found an example on reading property lists using Core Foundation
functions in the Property List Programming Guide
(http://developer.apple.com/documentation/Cocoa/Conceptual/PropertyLists/ReadWritePlistData/ReadWritePlistData.html#//apple_ref/doc/uid/10000048i-CH8-SW1).
Is this a safer way to get the data than relying on factory methods?
Thanks!
_______________________________________________
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