Transform Properties of an NSObject Into an NSDictionary

I needed a way to transform all the properties of an object that are not nil into an NSDictionary. I didn’t find a quick way to do it so I wrote my own NSObject category.

It uses the Objective-C runtime and the idea is really simple. I get a list of properties of the object’s class, loop on them getting their value, and only add them to the dictionary if they are not nil.

  • Kevin Muldoon

    Well done!! Was about to do this myself and your post saved me the trouble.

  • Tyegah

    This is very useful! Saved me a bunch of time. Thank you!