cocoa - Delegation in a NSThreaded Design? (iPhone) -


I am using very small web services in my app and I have lowered some roads which are not on scale Or work as desired.

Design Approach I'm Thinking: The task controller for the scene is asking for a set of data from the normal website class, this task will be a new NSThread -> it will start an object that is completely XML Receives and returns it to the Web Services class-> WebServicesClass now instantates an object that can only parse some XML coming from this specific web service. Parser then gives a good unit item to the webservice. Now WebserviceClass needs to inform viewController about this data.

The visualizer implements a web service class deaglelet and some representative methods, to see if the web service request has moved in a schematic form. Like - (void) aWebserviceFailed and - (zero) aWbserviceSuccess.

0.5 Since WebserviceClass is running a different NSThread, will it be a problem in calling the representative methods on the main NSThread in the main object?

1.0 I think that this design sounds because it completely involves retrieval, parsing and return of unit in different classes. However, for each separate webservice, I have to write the methods of the delegation and implement the delegation protocol on each step. That means implementing delegation methods for both objects that receive XML (start, fail, success) for WebserviceClass XML (start, fail, breakthrough) and parsing webserviceClass should be enabled and WebserviceClass should be enabled Delegate all these reactions to the controller, which is necessary to re-enforce delegation methods from WebSwivel (start, fail, success). Is there a very easy way to do this?

I have some design pattern experience, but not from the languages ​​that use the delegation, so the objective c. As in AS3 or Java, I have such incidents that inform objects and inform that whatever purpose the change was all about, I have read in the example code I have only NSNotifications (which can be used for AS3 or Java 'Event') Will be equal) will be used 0.1% times.

The design I have given will give me some things that are completely scalable for many web services and give me full control of where a possible error / exception occurs, but this loose coupling There are lots of codes to get.

1.1 or should I embrace the delegation approach completely and work :)

Thanks for any indication or assistance given to me source I am not asking for code or choice, and "in every situation you are considered the best practice in objective C": "

I recommend taking a look at ASIHttpRequest (attainable) and NSOperation + NSOperationQueue (docs) ). It does not seem that you should run a long lasting thread to talk to your web service at all times, unless you absolutely need a constant connection.

Actually ASIHttpRequest and NSOperation: Both networking and threading accessories are really good to multi-threading on the operating iPhone. Basically you create an operation (through the factory or for easy use), pop it in the queue And do something with the result.

What do you do with the result (this applies to your original scenario and 0.5 and 1.1 ) What is usually your The operation / thread will then call a didSucceedAtGettingWhatever or didFailWithError: (NSError *) method. There is a lot of delegation to request on the phone. If there are many representatives, you can use only the subject-supervisor, as you can in Java. For

1.0 , nobody in the end. Generally what we do, we have an operation deliaget and operation type. Based on the operation type successful or complete, we have different logic. This is not the biggest and there are many different ways to do this, but you have to have different logic for different programs, no matter what you do. Whether it is in a method or in many ways or not, it is up to you.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -