views:

42

answers:

0

I have a NSDictionary containing attributes I got from deserializing a JSON structure. I would like to initialize an object with these attributes, but replacing all the NSNull values with an empty string (all the object properties are strings). The object is being managed with Core Data.

I'm new to the language, so I'm not sure what's the ObjC way to do things. As I see it, I have a few options:

  • Replace all the nulls in the dict and then assign them (maybe put this into a constructor of some sort)
  • Rewrite all the setters that @synthesize helpfully generated to save a blank string when passed nils
  • Fix the JSON generation to replace nulls with blanks (it's being generated from a Rails app)

The first option makes the most sense. Being new to the language though, I don't know if there's some ObjC/CoreData magic that would let me default a blank string if I assigned a null value to a string property.

This language always has me on the fence - if I were writing C, I could assume the absence of magic, and if I were writing Ruby, I could assume the presence of magic. ObjC is always somewhere in between...