开发者

Creating a single JSON Parser/Network object

What I'm looking for is a point in the right direction of helping me create a better concept of what I need to do within my application design.

What I'm trying to do is have a class that will make network requests, IE: getUser, getTimeline, getLocation. Once the data has been recieived via -(void)connectionDidFinishLoading: have JSON (for my application I'm using TouchJSON) to parse the the data and with that data return an array or object of it.

All the above I can do, however I find I need to do it in every class I create which leads to a lot of code, and redundant code at that.

Basically if I want to do this approach now this is a rough walkthrough of what happens:

So for example:

  1. [View 1]->NetworkActivity Object -> getUser
  2. [NetworkActivity] -> getUser -> makeConnection -> parseObject -> return object
  3. [View 1]->getUser method is now complete and is empty, which in turn now means I have nothing to show

Now I understand that because im using Asynchronous request this is why this is happening, however what I'm after is a way to accomplish this approach without having to create several classes that basically do the same thing. I'm not looking f开发者_运维知识库or "the answer" just a nudge or a point in the right direction of something I can read or try that would better help me understand this.

Also I'm sorry if this was at all confusing, I tried to describe it as best as I could, but please do understand - I'm kinda confused at it all myself!


Take a look at Matt Gemmell's MGTwitterEngine which is a great example of how to develop a client that targets a specific API, Twitter. If you know that the serve implements RESTful web services, then you can also take a look at the iPhone on Rails project which implements a generic controller. You provide the model and the controller takes care of the REST.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜