Is it possible to narrow the allowed type of an ivar in a subclass. Something like this:
@interface person: NSObject {
NSArray *friendArray;
}
@interface
If the compiler says 'no' then that's your answer. I would use accessors:
//Person
-(NSArray *)friends;
//MutablePerson
-(void)addFriend:(person *)friend;
In the MutablePerson
you could declare another array to store friends
or you could access the ivar directly in addFriend:
:
-(void)addFriend:(person *)friend
{
_friendsArray = [_friendsArray arrayByAddingObject: friend];
}
Accessing ivars directly isn't smart. I would reconsider your class design. What's the rationale for having a mutable and immutable versions of person?