Wednesday, August 25, 2010

iOS - Accessing web services easily, now with blocks!!


The iPhone SDK 4 brought to us some very neat features. One of the most awesome and powerful are blocks.  
Blocks are like small procedures, that you can use as parameters to methods.
These structures exists already in many scripting languages, as ruby and python, and now we can also use its powers in ours iphone applications.
When we need to communicate with web services, we know how painful this task may be. Asynchronous operations, delegates, parsing json and xml responses. There are a lot of libraries that handle these tasks. I’ve commented already about a JSON parsing library here. But this library just parses JSON. It does not handle accessing the webservice, or error responses.
For that, i’ve found a great project hosted on github, called Seriously, that handles all of the tasks, and it uses blocks to simplify our code.

Continue reading on my tumblr

iOS - Parsing JSON


Very often we need to access some kind of service available on the internet to gather some data to work with. Most of nowadays services prefer to send data using the JSON format (learn more about json here). It’s simple and compared to XML, smaller.
In iOS there is no native way to work with json text, but there are some great library avaliable out there that make the job really easy. One of the best I know is the TouchJSON (a wiki about it is avaliable here). This library makes really simple the task to parse a JSON string.

Tuesday, August 24, 2010

How to load your data correctly in the background - iOS


Almost all view controllers need to load some data from the internet and interact with them.
This kind of task may sound simple at first, but as you will find out, there are some kind of complications, like autoreleasing objects with no autorelease pool in place, how to get notified when your data has been loaded and how to handle this data. Also all the updates to the view should be done in the main thread, not the background thread, to avoid possibly app crash.
To solve all these problems I’ve created a subclass of UiViewController that controls all the steps required to load the data the right way, and updates the view the right way.
Continue reading about this in my tumblr blog here