hi, I think i should be using selectors (or even a different paradigm), but even after R'ing TFM I can't figure out what i'm supposed to do. It's all related to callbacks from a delegate
I have my main Model object:
@implementation Model
@synthesize myConnection; // which is an NSURLConnection
...
-(void)someMethod{
MyConnectionDelegate *mcd = [[MyConnectionDelegate alloc]initWithCallingObject:self];
myConnection = [[NSURLConnection alloc] initWithRequest:requestForToken delegate:mcd];
...
}
-(void)didGetCalledBack:(NSArray *)resultArray{
NSLog(@"got the callback");
}
and then in my delegate:
@implementation MyConnectionDelegate
@synthesize callingObject; // which is of type id
@synthesize resultArray; // NSArray
-(id)initWithCallingObject:(id)caller{
...//std [self init] block
self.callingObject = caller;
return self;
...
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
...
}
//and all the other NSURLConnection delegate methods
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
...
// finish building array of results into self.resultArray
[self.callingObject didGetCalledBack:self.resultArray];
}
So...
1) I think i should be using selectors, or something else rather than hardcoding the fact that the caller (delegator?) needs to implement -didGetCalledBack
:
Right? IF so, how? (and why, other than cleanliness)
2) Or is my whole implementation wrong in the way i'm attempting to use a callback from the delegate of the NSURLConnection
back to the delegator wrong?
I've looked at the Apple samplecode etc but nothing i've seen ever has anything other than delegate:self
. Maybe i should have delegate:self too for the NSURLConnection
, but I'm making many connections and if i do delegate:self my delegate methods (like -didReceiveData
:) become a big mess of if (connection ==connection1){
type code.
thanks, richard