2

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

jwknz
  • 6,598
  • 16
  • 72
  • 115

2 Answers2

3

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.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • I'll look into that thanks:-) The app will use dates and also location coordinates, so I am not sure if the JSON way is going to work. It is also still on my list of Things to Learn:-) – jwknz Nov 13 '12 at 05:41
  • 1
    Note that you can represent dates as strings or as numbers if you need to store them in JSON. You'll just have to do that conversion yourself. Neither JSON nor property lists support location coordinates as a native type. – rob mayoff Nov 13 '12 at 05:42
  • Just one more question if you don't mind - Is XML on it's way out? I haven't much positive about it and JSON seems to be getting popular. Is it a personal preference for you, or is it just the way to go? – jwknz Nov 13 '12 at 05:49
  • I wouldn't say it's on its way out entirely. It's just overkill for many use cases, but there wasn't a popular, simpler alternative until JSON came along. This is the subject of many a blog post, so just type “xml sucks” or “json sucks” into Google when you feel like procrastinating. :) – rob mayoff Nov 13 '12 at 05:55
  • That's Cool:-) Jut gave me another reason to look into JSON - thanks for your advice and help:-) – jwknz Nov 13 '12 at 05:57
  • Also, if you're using plists and you're a command line guy, you will find the `plutil` and `/usr/libexec/PlistBuddy` commands useful. Google them. – rob mayoff Nov 13 '12 at 06:01
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.

Ben Lu
  • 2,982
  • 4
  • 31
  • 54
  • ah so I would need to parse into a normal xml file and then back again if it where to go back into the iOS app?? – jwknz Nov 13 '12 at 05:30
  • @JeffKranenburg You don't need to `parse` it to an xml. It *is* an xml. Just change its suffix to `xml` and you'll find it still recognizable by iOS as a `plist` and recognizable by other platforms. – Ben Lu Nov 13 '12 at 05:35
  • 1
    I just re-read your answer and found that my comment was based on what I thought you wrote:-) Thanks for the help:-) – jwknz Nov 13 '12 at 05:41