Using objc associated objet for an IBOutletCollection

30 Views Asked by At

I wanted to expose an IBOutletCollection for all my UIViewController classes without using inheritance, so I tried like that using the objc runtime, but the is never called. Any idea why ?

@interface UIViewController (MyCategory)

@property (nonatomic, strong) IBOutletCollection(UIView) NSArray<UIView *>    * items;

@end


@implementation UIViewController (MyCategory)

- (void)setItems:(NSArray<UIView *> *)items
{
    objc_setAssociatedObject(self, "items", items, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (NSArray<UIView *> *)items
{
    return objc_getAssociatedObject(self, "items");
}

@end
1

There are 1 best solutions below

0
LiohAu On

Problem solved, I was not using the IBOutletCollection for the view controller where I enabled the breakpoint :D