M
M
Makaveli2011-09-14 17:04:09
Objective-C
Makaveli, 2011-09-14 17:04:09

Catching an asynchronous NSURLConnection in Objective-C?

Hello. There is an app for ios.
The main controller FirstViewController
The RequestsClass
RequestsClass class contains the code that sends an asynchronous NSURLConnection, receives the data, and parses it.
The SendRequest method of the RequestsClass class is called from the FirstViewController.
The data is received and parsed, but in a new thread.
The question is - since the data is received and parsed in parallel with the execution of the FirstViewController code - how is it best to track inside the FirstViewController that the request is completed, the data is parsed and can be displayed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CLR, 2011-09-15
@CLR

There are three approaches (the most common, there are also exotic ones):
1. a global notification that anyone can subscribe to.
2. an indication for the requestclass of a special delegate with a special protocol by which it will notify that the download is completed (an error has occurred), respectively, firstviewcontroller will be this delegate.
3. Passing notification blocks to requestclass that will be called when the download is complete (well, or errors).
ps
I recommend reading the help / books before writing such code, these are the very basics and such a pattern is understood in every book about templates or almost every book about OOP. I can even recommend a specialized one for poppy drivers - "Cocoa Design Patterns" amzn.com/0321535022a book from the category, “not a line of code without reading”
pps
about threads is not entirely clear, or I did not understand the idea, or you do not quite understand what is happening.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question