0

I'm trying to create a class which contains different method, each one of these methods will perform some http requests operations and return a result to the caller method.

for example:

UserOperations *op = [[UserOperations alloc] init];
int age = [op getUserAge];

the method "getUserAge" will call a web service and do some xml parsing to return a value (the age) to the caller.

what's the best and right way to implement it.

thanks

Ilanchezhian
  • 17,426
  • 1
  • 53
  • 55
Kassem
  • 1,481
  • 3
  • 20
  • 42
  • possible duplicate of [Cocoa - Return information from NSOperation](http://stackoverflow.com/questions/1297733/cocoa-return-information-from-nsoperation) – Ilanchezhian May 09 '12 at 10:44

2 Answers2

1

You need to implement delegate pattern here.

See Protocols and delegates in iOS. Please visit here and Apple documentation

And, also see a similar question asked on SO here

Community
  • 1
  • 1
Ilanchezhian
  • 17,426
  • 1
  • 53
  • 55
0

for every webservice, you should have to separate it from your controller, and then separate the controller from your UI class.

like

UILayer //invoke method of controller class and pass the delegate of viewController and selector to which at the end you want to return

Control Layer // get the data along with delegate to UIlayer and selector to uiLayer, and call the webservice

Webservice Layer // receive the data from controll layer, call the webservice from server, get the response and pass to parser layer along with its delegate(webservice)

Parser Layer // get data from webervice layer and parse it

//////////////////////////////////////////////////////

now you are going back

// webservice layer has the delegate stored in it that to UI layer along with the selecter, after parsing the responsed data, it will call the UILayer with the parsed data.

// ui layer will display/process it

Saad
  • 8,857
  • 2
  • 41
  • 51