FluidGroup / TextureSwiftSupport

A library that gains Texture(AsyncDisplayKit) more power in Swift.
https://medium.com/@muukii/creating-ui-with-like-swiftuis-syntax-by-the-power-of-texture-framework-4d6de571ee86
MIT License
239 stars 28 forks source link

Texture with Tuist #117

Open 98prabowo opened 1 month ago

98prabowo commented 1 month ago

My project is using Texture on production. I want to migrate my dependency manager from Cocoapods to Tuist. All dependency are good, but when I first run my project I got this error:

`Assertion failure in IMP ASReplaceMethodWithBlock(__unsafe_unretained Class _Nonnull, SEL _Nonnull, __strong id _Nonnull)(), ASInternalHelpers.mm:106`. 

I look on the Texture source code and see that this block make the program crash:

#if ASDISPLAYNODE_ASSERTIONS_ENABLED
  if (self != [ASDisplayNode class]) {

    // Subclasses should never override these. Use unused to prevent warnings
    __unused NSString *classString = NSStringFromClass(self);

    ASDisplayNodeAssert(!ASDisplayNodeSubclassOverridesSelector(self, @selector(calculatedSize)), @"Subclass %@ must not override calculatedSize method.", classString);
    ASDisplayNodeAssert(!ASDisplayNodeSubclassOverridesSelector(self, @selector(calculatedLayout)), @"Subclass %@ must not override calculatedLayout method.", classString);
    ASDisplayNodeAssert(!ASDisplayNodeSubclassOverridesSelector(self, @selector(layoutThatFits:)), @"Subclass %@ must not override layoutThatFits: method. Instead override calculateLayoutThatFits:.", classString);
    ASDisplayNodeAssert(!ASDisplayNodeSubclassOverridesSelector(self, @selector(layoutThatFits:parentSize:)), @"Subclass %@ must not override layoutThatFits:parentSize method. Instead override calculateLayoutThatFits:.", classString);
    ASDisplayNodeAssert(!ASDisplayNodeSubclassOverridesSelector(self, @selector(recursivelyClearContents)), @"Subclass %@ must not override recursivelyClearContents method.", classString);
    ASDisplayNodeAssert(!ASDisplayNodeSubclassOverridesSelector(self, @selector(recursivelyClearPreloadedData)), @"Subclass %@ must not override recursivelyClearFetchedData method.", classString);
  } else {
    // Check if subnodes where modified during the creation of the layout
      __block IMP originalLayoutSpecThatFitsIMP = ASReplaceMethodWithBlock(self, @selector(_locked_layoutElementThatFits:), ^(ASDisplayNode *_self, ASSizeRange sizeRange) {
          NSArray *oldSubnodes = _self.subnodes;
          ASLayoutSpec *layoutElement = ((ASLayoutSpec *( *)(id, SEL, ASSizeRange))originalLayoutSpecThatFitsIMP)(_self, @selector(_locked_layoutElementThatFits:), sizeRange);
          NSArray *subnodes = _self.subnodes;
          ASDisplayNodeAssert(oldSubnodes.count == subnodes.count, @"Adding or removing nodes in layoutSpecBlock or layoutSpecThatFits: is not allowed and can cause unexpected behavior.");
          for (NSInteger i = 0; i < oldSubnodes.count; i++) {
              ASDisplayNodeAssert(oldSubnodes[i] == subnodes[i], @"Adding or removing nodes in layoutSpecBlock or layoutSpecThatFits: is not allowed and can cause unexpected behavior.");
          }
          return layoutElement;
      });
  }
#endif

I realize that from my previous config, this block doesn't run. And ASDISPLAYNODE_ASSERTIONS_ENABLED is asserted from this:

#if !defined(NS_BLOCK_ASSERTIONS)
  #define ASDISPLAYNODE_ASSERTIONS_ENABLED 1
#else
  #define ASDISPLAYNODE_ASSERTIONS_ENABLED 0
#endif

So, I set ENABLE_NS_ASSERTIONS to NO for TextureSwiftSupport package config. And this error is gone.

But then I got new error whenever I init any node that inherit from ASDisplayNode.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TextureSwiftSupport.NamedDisplayNodeBase scheduleIvarsForMainThreadDeallocation]: unrecognized selector sent to instance 0x13c01c000'

I still don't have any clue about this exception. Here my sandbox to reproduce this crash: https://github.com/98prabowo/TextureDebug

Xcode: 15.4 Texture: 3.0.2 TextureSwiftSupport: 3.20.1

muukii commented 1 month ago

interesting. I also use Tuist for this. but it works well.

muukii commented 1 month ago

I guess this target needs flags for objc like -ObjC

CleanShot 2024-05-31 at 18 47 54@2x