0

Trying to use ASCollectionDataSourceInterop to combine UICollectionViewCell and ASCellNode in one data source as it is described here

http://texturegroup.org/docs/uicollectionviewinterop.html

However I run into issue here, because

func collectionView(_ collectionView: ASCollectionView, nodeForItemAt indexPath: IndexPath) -> ASCellNode {
        return nil
}

Doesnt work in swift, maybe there is a way to workaround in swift

Andrius Steponavičius
  • 8,074
  • 3
  • 22
  • 25
  • cellForItemAtIndexPath: called? – Bimawa Dec 07 '17 at 06:59
  • yes, just no way of returning null in swift – Andrius Steponavičius Dec 08 '17 at 17:14
  • @Andeius, can u share simple example? – Bimawa Dec 08 '17 at 17:30
  • @AndriusSteponavičius I may be misunderstanding your question, but why would you ever return `nil` for `nodeForItemAtIndexPath`? Even with the standard `cellForRowAtIndexPath` or `cellForItemAtIndexPath`, they don't allow for nil to be returned. We use Texture (AsyncDisplayKit) extensively in our project (100% swift) and have not had any swift related issues or constraints. – Stephen Silber Jan 08 '18 at 21:30
  • @StephenSilber it's because you haven't tried interop :) Facing the same issue as Andrius right now – Alexander Telegin May 24 '20 at 22:53
  • You can even check out the documentation - there is no Swift version for the code example here: https://texturegroup.org/docs/uicollectionviewinterop.html – Alexander Telegin May 24 '20 at 22:55

1 Answers1

1

Found a solution: just make the return type an implicitly unwrapped optional:

func collectionNode(_ collectionNode: ASCollectionNode,
                    nodeBlockForItemAt indexPath: IndexPath) -> ASCellNodeBlock! {
    return optionalNodeBlock
}

The compiler does warn you about the type mismatch, but everything works well

Alexander Telegin
  • 665
  • 1
  • 7
  • 22