1

I am trying to set up protocols and delegates from a view controller through one class to another class, but am very lost.

Basically, I have a viewcontroller a connection class and a parser class. This is the process that happens

The viewcontroller creates a connection class object which queries my db via NSURLConnection class delegates and gets a bunch of data. Then the connection class creatings a parser class object and passes all this data over to be parsed...

what I am not yet able to do is pass the data back from the parser class to the viewcontroller, this is because some how I have to set the delegate of the parser class from the view controller through the connection class object... but have no idea how to do it...

I am hoping someone here can help me.. I have several questions that have culminated to the point in which I have come to the conclusion (with lots of help) that this is my problem.

so the question is - how do I set the protocols and delegates of the parser class object from the viewcontroller via the connection class object.

C.Johns
  • 10,185
  • 20
  • 102
  • 156
  • This may help you: http://stackoverflow.com/questions/7215698/what-exactly-does-delegate-do-in-xcode-project/7215969#7215969 – bryanmac Mar 15 '12 at 03:12
  • dose your solution cover the fact Im going through another class not just the usual communicating between two?.. sorry I have just about done my dash today.. starting to get confused by everything but I don't want to ruin my chance of getting some help..... – C.Johns Mar 15 '12 at 03:42

2 Answers2

2

You have three classes: ViewController, ConnectionClass, and ParserClass. Ultimately the ViewController class needs to received parsed data. So, the ViewController is the delegate of the ConnectionClass and the ConnectionClass is the delegate of the ParserClass. When the parser completes parsing, it returns the data to the ConnectionClass via a delegate method. Then, in turn, the ConnectionClass returns data to the ViewController.

You could also achieve the same effect with less formality using a blocks-based API between classes. I'm sure there are other ways too.

FluffulousChimp
  • 9,157
  • 3
  • 35
  • 42
  • yes, you put that perfectly. thats exactly what I am trying to do. – C.Johns Mar 15 '12 at 03:25
  • +1 - the nice thing about the layered classes here and delegates is they are loosely coupled. they are not hard wired to each other. Each layer dictates the answers it needs and the layer above it signs up to answer those questions. I've also used that when composing more complex views out of simpler views. Without the coupling, the simple views can be re-used as long as the consumer can answer those questions. – bryanmac Mar 16 '12 at 00:08
0

I think I know what you are trying to do. In this case I don't think delegates are the way to go. NSNotification can be used so that you set up your VC to listen for the parser to get finished with the parsing and then it posts a notification with the parsed object.

LJ Wilson
  • 14,445
  • 5
  • 38
  • 62
  • 1
    As an aside, what are you parsing? I have really learned to like AFNetworking using JSON and using this makes my NetworkClient class really lightweight and efficient. – LJ Wilson Mar 15 '12 at 03:12
  • what is NSNotification like with large amounts of data + frequent data parsing? is it robust enough to handle this? I want to end my life atm lol this whole process has been such a pain in the butt – C.Johns Mar 15 '12 at 03:12
  • well the data packet coming back is our own formatted data, it has a segment of xml that holds the actual data I am parsing. the rest are just format specifiers such as length, request number, cache etc. – C.Johns Mar 15 '12 at 03:13