Using Plists in other environments
Asked Answered
S

2

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

Scotfree answered 13/11, 2012 at 5:23 Comment(0)
U
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.

Urumchi answered 13/11, 2012 at 5:28 Comment(3)
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??Scotfree
@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.Urumchi
I just re-read your answer and found that my comment was based on what I thought you wrote:-) Thanks for the help:-)Scotfree
H
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.

Hussite answered 13/11, 2012 at 5:38 Comment(6)
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:-)Scotfree
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.Hussite
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?Scotfree
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. :)Hussite
That's Cool:-) Jut gave me another reason to look into JSON - thanks for your advice and help:-)Scotfree
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.Hussite
U
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.

Urumchi answered 13/11, 2012 at 5:28 Comment(3)
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??Scotfree
@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.Urumchi
I just re-read your answer and found that my comment was based on what I thought you wrote:-) Thanks for the help:-)Scotfree

© 2022 - 2024 — McMap. All rights reserved.