I think, you can use category on their common ancestor UIView. You can only share common methods, not instance variables.
Lets see how to use it.
For example you have custom UITableViewCell
@interface PersonTableCell: UITableViewCell
@property (nonatomic, weak) IBOutlet UILabel *personNameLabel;
- (void)configureWithPersonName:(NSString *)personName;
@end
@implementation PersonTableCell
- (void)configureWithPersonName:(NSString *)personName {
self.personNameLabel.text = personName;
}
@end
And UICollectionViewCell
@interface PersonCollectionCell: UICollectionViewCell
@property (nonatomic, weak) IBOutlet UILabel *personNameLabel;
- (void)configureWithPersonName:(NSString *)personName;
@end
@implementation PersonCollectionCell
- (void)configureWithPersonName:(NSString *)personName {
self.personNameLabel.text = personName;
}
@end
Two share common method configureWithPersonName: to their ancestor UIView lets create category.
@interface UIView (PersonCellCommon)
@property (nonatomic, weak) IBOutlet UILabel *personNameLabel;
- (void)configureWithPersonName:(NSString *)personName;
@end
@implementation UIView (PersonCellCommon)
@dynamic personNameLabel; // tell compiler to trust we have getter/setter somewhere
- (void)configureWithPersonName:(NSString *)personName {
self.personNameLabel.text = personName;
}
@end
Now import category header in cell implementation files and remove method implementations. From there you can use common method from category.
The only thing that you need to duplicate is property declarations.