PIXEL
DOCK

I like the smell of Swift in the morning…

A little category to get an NSDictionary from an NSString containing a plist

Posted: | Author: | Filed under: iOS, Objective-C | Tags: , , | 2 Comments »

I really like the plist format. Being able to transform a plist file into a NSDictionary with one line of code really appeals to the lazy guy in me. So when our backend developer asked me what my preferred format for server responses would be, I told him to send his responses in plist format. That’s when I came across a little problem: When accessing the response body of the request, all I got was a NSString. The string contained the plist, but it was still a string and not the usual XML structure that you normally get when you open a plist file.

I found a way to parse a NSString into a NSDictionary on StackOverflow (thanks to Peter N Lewis for his answer).

So I decided to write a little category to extend NSDictionary so that it can initialize a NSDictionary with a plist NSString:

Feel free to use it in your own projects.

2 Comments

  • 1

    Eduardsaid at

    Thank you very much for useful category for iOS developing!!!

  • 2

    kashyapsaid at

    Thanks for your such helpful snippet. it works well for me.


Leave a Reply