Parse an iOS plist on Android
I was implementing a feature in the CalorieCount Android App the other day that was previously implemented in the iOS version of that same app. Just needed to show a list of timezones based on what country was selected. Not rocket science at all, but the iOS implementation was storing the data in a plist file, with a <dict> element inside. So rather than take that data and try to translate it to something more ‘android specific’ … I decided to just use the file as is. The biggest benefit was that in the future if we ever had to update the file, I could update it in place, and simply copy it over to the other platform.
So I copied the file into my xml folder, and wrote this simple parser that reads the file in, and parses it into a HashMap
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
The way I look at it, may as well reuse what we’ve got, and spend less time yak shaving (ie. translating between platforms) … git ‘er done!