Reputation: 309
I am looking for good pattern for such a situation. Let's we have class with delegate:
@protocol MyDelegate
-(void) someEvent;
@end
@interface MyServiceClass
@property (nonatomic,weak) id<MyDelegate> delegate;
@end
And we have two instances of this class. For example serviceObject1 and serviceObject2. Now in our controller we want to receive events from both of instances:
-(void) registerDelegates {
serviceObject1.delegate=self;
serviceObject2.delegate=self;
}
-(void) someEvent {
// do something
}
All is good except that events from both instances will be thrown to one someEvent method. For me will be more comfortable to separate events from serviceClass1 and serviceClass2 to different methods.
I saw three approaches but does not like any of them:
May be exists another solution that i missed?
Upvotes: 1
Views: 619
Reputation: 3251
The way this is handled is by passing the MyServiceClass instance as one of the method parameters, basically what you wrote for #1.
That's how Apple does it and it's kind of standard practice.
@protocol MyDelegate
-(void) someEventFromService:(MyServiceClass *serviceClass);
@end
Upvotes: 3