diff --git a/Source/ASNodeController+Beta.h b/Source/ASNodeController+Beta.h index d443c45b3..7c75c5eec 100644 --- a/Source/ASNodeController+Beta.h +++ b/Source/ASNodeController+Beta.h @@ -18,10 +18,18 @@ #import #import // for ASInterfaceState protocol +// Until an ASNodeController can be provided in place of an ASCellNode, some apps may prefer to have +// nodes keep their controllers alive (and a weak reference from controller to node) +#define INVERT_NODE_CONTROLLER_OWNERSHIP 0 + /* ASNodeController is currently beta and open to change in the future */ @interface ASNodeController<__covariant DisplayNodeType : ASDisplayNode *> : NSObject +#if INVERT_NODE_CONTROLLER_OWNERSHIP +@property (nonatomic, weak) DisplayNodeType node; +#else @property (nonatomic, strong) DisplayNodeType node; +#endif - (void)loadNode; diff --git a/Source/ASNodeController+Beta.m b/Source/ASNodeController+Beta.m index d79d71758..02efdc225 100644 --- a/Source/ASNodeController+Beta.m +++ b/Source/ASNodeController+Beta.m @@ -16,9 +16,30 @@ // #import "ASNodeController+Beta.h" - #import "ASDisplayNode+FrameworkPrivate.h" +#if INVERT_NODE_CONTROLLER_OWNERSHIP + +@interface ASDisplayNode (ASNodeController) +@property (nonatomic, strong) ASNodeController *asdkNodeController; +@end + +@implementation ASDisplayNode (ASNodeController) + +- (ASNodeController *)asdkNodeController +{ + return objc_getAssociatedObject(self, @selector(asdkNodeController)); +} + +- (void)setAsdkNodeController:(ASNodeController *)asdkNodeController +{ + objc_setAssociatedObject(self, @selector(asdkNodeController), asdkNodeController, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +@end + +#endif + @implementation ASNodeController @synthesize node = _node; @@ -49,6 +70,9 @@ -(void)setNode:(ASDisplayNode *)node { _node = node; _node.interfaceStateDelegate = self; +#if INVERT_NODE_CONTROLLER_OWNERSHIP + _node.asdkNodeController = self; +#endif } // subclass overrides