Good Morning!
So I spend the evening yesterday trying to understand what I have missed on all this. My approach now is the following:
- I have created a class DataAccess which is a singleton class. This class is responsible to the URLConnection and for now(I indend to make a seperate parser class) also parsing. To make this class singleton I have the folloging definition in the .h file:
Code:
+ (DataAccess *) sharedDataAccess;
and this in the .m file:
Code:
+ (DataAccess *)sharedDataAccess {
static DataAccess *sharedDataAccess;
@synchronized(self) {
if(!sharedDataAccess) {
sharedDataAccess = [[DataAccess alloc] init];
}
}
return sharedDataAccess;
}
The rest of this class is like the code parts above in this thread. The warnings about the selector are still there and I suppose this may be because I do not really understand this part... :-(
From my AppDelegate I intend to fill some arrays to be used in the views of the app. So I have to call the function
Code:
- (void) startLoadingURL:(NSURL *) url withCallbackTarget:(id) t andSelector:(SEL) s{
in order to do this.
The DataAccess object has the class method sharedDataAccess and to call this I do not have create an instance of a DataAccess class. It may be called with
Code:
[DataAccess sharedDataAccess];
BUT - the question here is: what is in this sharedDataAccess? As I can see it, the data has to be saved into this object, right?
So, (if we skip the parser for now) this means I have to get the data into this variable in the method
Code:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
In this method I get the data, selector and the target for a specific connection. I suppose the selector here is the method to use when "doing something" with this data. The data is the data - but what about the target? That must be the reciever, as self if the parser happend to be defined in the same class, or am I wrong here?
So, with
Code:
[self performSelector:(SEL)selector withObject:(id)data];
a call for a specific selector for a specific connection should be called and the current data will be send into this method (selector). The target is the class it self in this case...when the parser is defined in the DataAccess class.
Is this all wrong or is at least the thoughts about the structure of this right???
My questions now are:
- how to get rid of the errors regarding the selector. What on earth am I missing here? I think I understand the meaning with a selector but there must be something in the chain above that I am doing wrong.
- how to call this DataAccess from my AppDelegate class? If I call
Code:
[DataAccess sharedDataAccess];
this is returning an empty object, right? So Should I, in this method, call the startLoadingURL method or should I do this from outside (ie from my AppDelegate)?
- How do I, in my DataAccess class fill the sharedDataAccess object with data to be used in for instance an array later on in my app?
I am sorry for me asking so many questions, but I really want to get this right and I do really want to understand it. I have read about the issuses in one of my iPhone books (iPhone SDK3 Programming, Maher Ali) and that did not help me futher. I am sure that if I could understand the structure of this all, I could implement it properly.
I am very very greatful if you would like to go on heling me!
Thanks in advance!
MACloop