Tag Archives: Parsing

Architecting with Blocks part 2

(Note: This is part 2 of a series of posts about Architecting an application using blocks in objective-c. By no means I am an expert on using blocks, and also it’s not the intention of this series to teach you how to use blocks. You can check this for that. To finalise, I am sure there are better ways to use blocks while architecting an app: use this at your own risk. :))

This is the final post from a 2 parts series that I start a long ago. In this case I won’t show any snippet of code, I will give away an entire sample. My approach about this matter, change in the meantime, nonetheless hope you enjoy it. You can find it here .

Advertisements
Tagged , , , , , , ,

JSON oh JSON

While I do prefer to use JSON, instead of XML. I use to prefer it, but for the wrong reasons. Well, not wrong, but you can always improve right? So why do I love it?

– Lighter than XML

NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:myJsonData options:kNilOptions error:&error];

Well the first is really nice, but it doesn’t really help us out, at least directly. The second is just glorious. You get a NSDictionary, that you can use across all your app, with one single line. What’s the catch? In terms of visibility is just wrong. I know I have my data there, but does the next guy that is going to support my app knows that? I can leave some comments…. I promise.. Instead, just create a class to hold that data, and give it some meaning. What I would recomment is something like this:

- (id)initWithDictionaryFromJSON:(NSDictionary*)dictionary;

It is boring, but it gives visibility, helps maintenance,  and gives meaning to your data.

Tagged , , , ,