I assign protocols in pairs of classes that follow the inheritance tree. For example:
first grade
@protocol LevelOne
- (void) functionA
@end
@interface BaseClass : NSObject <LevelOne> {
}
second class
@protocol LevelTwo <LevelOne>
- (void) functionB
@end
@interface SubClass : BaseClass <LevelTwo> {
}
Later I assign the class as delegation properties of other classes
base class
@interface AppClass : NSObject {
@protected
id<LevelOne> levelOneDelegate;
}
@property (assign) id<LevelOne> levelOneDelegate;
subclass
@interface AppClassesFriend : AppClass {
@protected
id<LevelTwo> levelTwoDelegate;
}
@property (assign) id<LevelTwo> levelTwoDelegate;
At the end of this journey, AppClassesFriend has 2 properties.
"levelOneDelegate" has access to the function "functionA" when a BaseClass object is assigned to it.
However, I find that "levelTwoDelegate" only has access to "function B" (it is assigned a SubClass object).
So that the AppClassesFriend application can use both functions, it seems I need to assign BOTH levelOneDelegate AND levelTwoDelegate.
"levelTwoDelegate" ? "SubClass".
, :
SubClass *s = [SubClass alloc];
AppClassesFriend *a = [AppClassesFriend alloc];
a.levelTwoDelegate = s;
AppClassesFriend (a) :
[self.levelTwoDelegate functionA]; <---- this is never found
[self.levelTwoDelegate functionB];
, ,
a.levelOneDelegate = s;
, - , . , , , "levelTwoDelegate" , , B?