This code is pretty simple, is it correct? I don't know if I should be retaining the delegate passed in via the init method.
@interface SomeClass : NSObject {
SomeClassDelegate *someClassDelegate;
}
-(id)initWithDelegate:(SomeClassDelegate *)delegate;
@end
@implementation SomeClass
-(id)initWithDelegate:(SomeClassDelegate *)delegate
{
[delegate retain]; // should I be doing this?
someClassDelegate = delegate;
}
-(void)dealloc
{
[delegate release]; // obviously only do this if I DO need to retain it
[super dealloc];
}
@end
My initial thought is no, however this bit of code seems to hint otherwise. I know I can't rely on retain counts, but I'd like to know the proper way to deal with delegates.
// self's retain count is 1
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:req delegate:self];
// the retain count is now 2, did the init of URLConnection retain self?