MarkosDarkin MarkosDarkin - 1 month ago 6x
Swift Question

Swift - how do i convert a regular XML file to a .plist XML file

I searched the web for this one and mostly found Obj-C answers or outdated answers so ill simply post the question and hope for the best :)

Im working with a team of Android Developers while im working on IOS. they use XML files for a lot of data. since we want the data between us to stay consistent - we want to be able to have shared XML files to use in our projects.
I know .plist is basically a type of XML, but i want to be able to get the regular shared XML file and turn it into a .plist and then use it in my IOS project.

any known method of doing it at all? if so, is it possible to do it automatically somehow? (script or something of that sort. maybe even do it locally inside the application)

Thanks for the help


A .plist file is a very specific XML file with only a small set of keys allowed. A random XML file will not be convertible to a .plist file.

Try converting your file to JSON first. If you can convert it to JSON you will be able to automatically convert it to a .plist after that using the plutil command with the xml1 or binary1 format.

plutil -convert xml1 -o output.plist input.json

If you can't convert it to JSON, you can keep your XML file as is and parse it in your app using NSXMLParser. XML is harder to parse than .plist or JSON files, but aside from that the difference should be minimal.