I'm working with a custom delegate and protocol functionality.
I implemented my class like follows:
@protocol MyDelegate <NSObject>
@required
- (void)update;
@end
@interface MyHandlerClass : NSObject
{
id <MyDelegate>delegate;
}
@property (nonatomic, weak) id <MyDelegate>delegate;
@end
My implementation class looks like:
@implementation MyHandlerClass
@synthesize delegate = _delegate;
- (void)updateRequired: (id)sender
{
if(delegate)
{
[delegate update];
}
}
@end
And from another class I'm setting it like:
[sharedManager setDelegate:self];
But when the updateRequired
is triggered it is showing as nil
.
Then I added a setter method like:
- (void)setDelegate:(id<MyDelegate>)aDelegate
{
delegate = aDelegate;
}
Everything works fine !!!
Then I changed the updateRequired
method (without custom setter) like:
- (void)updateRequired: (id)sender
{
if(_delegate)
{
[_delegate update];
}
}
It is also working fine !!!
I couldn't find why it is not worked for the first case and why it is worked for the other two cases ?
Please help me to find the issue, Thanks in advance