Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit c9ac554

Browse files
committed
[ASDisplayNode] Add assertion to +initialize warning developers who override and do not call super.
If a developer makes this error, it would prevent calls to key lifecycle methods, such as -layoutSpecThatFits:. Although the superclasses of ASDisplayNode do not implement +initialize, a super call is added here for consistency.
1 parent 44c860b commit c9ac554

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

AsyncDisplayKit/ASDisplayNode.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
178178

179179
+ (void)initialize
180180
{
181+
[super initialize];
181182
if (self != [ASDisplayNode class]) {
182183

183184
// Subclasses should never override these
@@ -199,8 +200,11 @@ + (void)initialize
199200
BOOL instancesOverrideRespondsToSelector = ASSubclassOverridesSelector([NSObject class], self, @selector(respondsToSelector:));
200201
struct ASDisplayNodeFlags flags = GetASDisplayNodeFlags(self, nil);
201202
ASDisplayNodeMethodOverrides methodOverrides = GetASDisplayNodeMethodOverrides(self);
203+
204+
Class initializeSelf = self;
202205

203206
IMP staticInitialize = imp_implementationWithBlock(^(ASDisplayNode *node) {
207+
ASDisplayNodeAssert(node.class == initializeSelf, @"Node class %@ does not have a matching _staticInitialize method; check to ensure [super initialize] is called within any custom +initialize implementations! Overridden methods will not be called unless they are also implemented by superclass %@", node.class, initializeSelf);
204208
node->_flags = (classOverridesRespondsToSelector || instancesOverrideRespondsToSelector) ? GetASDisplayNodeFlags(node.class, node) : flags;
205209
node->_methodOverrides = (classOverridesRespondsToSelector) ? GetASDisplayNodeMethodOverrides(node.class) : methodOverrides;
206210
});

0 commit comments

Comments
 (0)