I'm not sure if this is possible, but I've seen people do crazy things with regex and other tools.
I want to convert this plist to an Objective-C literals:
<dict>
<key>ar</key>
<array>
<string>+54## #### ####</string>
<string>## #### ####</string>
</array>
<key>at</key>
<array>
<string>+43 1 ########</string>
<string>+43 ############</string>
</dict>
converted to:
NSDictionary *dic = @{
@"ar" : @[@"+54## #### ####", @"## #### ####"],
@"at" : @[@"+43 1 ########",@"+43 ############"]
};
Is it possible to automate such conversion? This guy did something similiar: he parsed a PHP list into an NSDictionary using VIM.
Plist don't have a separate 'format' for use in code (this question doesn't quite make sense as-is). You either want to 1. generate Objective-C code which initializes the dictionary with these values, or 2. initialize the dictionary using the file, for which you can write
Edit: so you want to generate Objective-C code that in turn will reproduce the same dictionary. For this, you need to re-print the contents of the dictionary in a formatted way. You can write a program like this:
This program will generate (hopefully syntax error-free) Objective-C initialization code out of the provided property list which can be copy-pasted to a project and be used.
Edit: I just run the program on a stripped version of the plist file OP has provided (the original file was way too large, so I cut it a bit) and it generated the following code:
To verify it was really valid, I pasted this into the middle of an
int main()
to a file called 'test.m', so I got this program:To verify, I run
clang -o test test.m -lobjc -framework Foundation
and surprise, surprise:It worked.
Edit 2: I made this a command line utility, just to facilitate further work - who knows, this may be useful in the future. Plist2ObjC
Hope this helps.