Using Plists in other environments

2019-07-23 17:25发布

问题:

Are Pists limited to be used on a OSX and iOS system?

I am thinking of the architecture of my app and one of many ways to import data into an iPhone app is via a Plist and you can save to it as well.

Now if say that plist is able to be exported away from the app in it's raw format, will it be accesible by say Android or Windows Phone format? Or will it need to be converted?

The way I understand it is that a Plist is a XML format right? I am probably wrong, but that is what I can make up of the file when I look at it.

Cheers

回答1:

You are right. Plist is actually an xml formatted file with a plist header and can be parsed by any xml parser. Since xml can be used in variety of environments, plist can do the same thing. Just change its suffix to xml and you can do whatever you want.



回答2:

A property list, as explained in the Property List Programming Guide, is any of these things:

  • a string
  • a blob of binary data
  • a date
  • an integer
  • a floating-point number
  • a Boolean value
  • an array of property lists
  • a dictionary whose keys are strings and whose values are property lists

There are two common ways to serialize a property list.

One is the XML format, which you are aware of. This format is sort of documented on the plist(5) man page.

The other is a binary format, which is much more compact and faster to encode and decode. It is not officially documented anywhere, but its format is described in the comments and code of CFBinaryPlist.c, which is included in the open source release of Apple's Core Foundation framework.

If your data doesn't use dates or binary blobs, you may find it easier to use JSON than an XML plist. Starting in iOS 5 and OS X 10.7 (Lion), Apple provides the NSJSONSerialization class to serialize and deserialize JSON, and there are JSON libraries for just about every platform and language under the sun.