• 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: dataFromPropertyList:format:errorDescription:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dataFromPropertyList:format:errorDescription:


  • Subject: Re: dataFromPropertyList:format:errorDescription:
  • From: Chris Kane <email@hidden>
  • Date: Fri, 26 Sep 2003 18:42:31 -0700

Generally when there are a pair of operations to do A and to do the "inverse of A", you should use both pieces of that pair, in my opinion. Both for code consistence and readability, but also because the pair is probably designed to work together, and doing other things may or may not work.

A classic example comes from the NSPasteboard API, where there are set and get methods for three cases, data, strings, and property lists:

- (BOOL)setData:(NSData *)data forType:(NSString *)dataType;
- (NSData *)dataForType:(NSString *)dataType;

- (BOOL)setPropertyList:(id)plist forType:(NSString *)dataType;
- (id)propertyListForType:(NSString *)dataType;

- (BOOL)setString:(NSString *)string forType:(NSString *)dataType;
- (NSString *)stringForType:(NSString *)dataType;

Yet, you'll have people call setString:forType: on one end, then try to call -propertyListForType: on the other end (well, strings are property lists, aren't they?). But you get entirely different results from setString:forType: and setPropertyList:forType:, and the get method of one pair cannot understand the data written for the set method of another. And of course if you mix the data and convenience pairs, you won't necessarily get something that works either.

So I would use NSPropertyListSerialization for both your reading and writing.

Chris Kane
Cocoa Frameworks, Apple


On Sep 24, 2003, at 12:52 PM, Steve Mykytyn wrote:

I'm saving some application-wide "bookmark" data (NSMutableArray,
NSMutableDictionary, etc. in a tree and leaf structure) using

[NSPropertyListSerialization dataFromPropertyList: ...

and I read it back in when my application starts up using

[NSArray arrayWithContentsOfFile:plistPath]

It seems like the arrays and dictionaries I read back in are mutable -
which is what I want, but not what the Cocoa documentation seems to
imply.

Am I likely to get in trouble with this approach? - or put another way,
should I be using

[NSPropertyListSerialization
propertyListFromData:mutabilityOption:format:errorDescription:

with the mutability option set to NSPropertyListMutableContainers?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >dataFromPropertyList:format:errorDescription: (From: Steve Mykytyn <email@hidden>)

  • Prev by Date: Re: nextKeyView broken
  • Next by Date: Re: loadNibNamed:owner: Who disposes of the loaded objects?
  • Previous by thread: Re: loadNibNamed:owner: Who disposes of the loaded objects?
  • Next by thread: Cocoa Java: this class is not key value coding-compliant
  • Index(es):
    • Date
    • Thread