mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
[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.
This commit is contained in:
@@ -178,6 +178,7 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
[super initialize];
|
||||
if (self != [ASDisplayNode class]) {
|
||||
|
||||
// Subclasses should never override these
|
||||
@@ -199,8 +200,11 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
||||
BOOL instancesOverrideRespondsToSelector = ASSubclassOverridesSelector([NSObject class], self, @selector(respondsToSelector:));
|
||||
struct ASDisplayNodeFlags flags = GetASDisplayNodeFlags(self, nil);
|
||||
ASDisplayNodeMethodOverrides methodOverrides = GetASDisplayNodeMethodOverrides(self);
|
||||
|
||||
Class initializeSelf = self;
|
||||
|
||||
IMP staticInitialize = imp_implementationWithBlock(^(ASDisplayNode *node) {
|
||||
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);
|
||||
node->_flags = (classOverridesRespondsToSelector || instancesOverrideRespondsToSelector) ? GetASDisplayNodeFlags(node.class, node) : flags;
|
||||
node->_methodOverrides = (classOverridesRespondsToSelector) ? GetASDisplayNodeMethodOverrides(node.class) : methodOverrides;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user