0

I'm using Async in my IOS app and need a fluid scroll for the CollectionView so i'm trying to use ASyncDisplayKit that seems to be made to have smooth scroll.

All the samples are made in ObjectiveC, i would like to translate this part of code:

- (ASCellNodeBlock)tableView:(ASTableView *)tableView    nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath
{
  PhotoModel *photoModel = [_photoFeed objectAtIndex:indexPath.row];
    // this will be executed on a background thread - important to make sure it's thread safe
    ASCellNode *(^ASCellNodeBlock)() = ^ASCellNode *() {
      PhotoCellNode *cellNode = [[PhotoCellNode alloc] initWithPhotoObject:photoModel];
      return cellNode;
    };

    return ASCellNodeBlock;
}

Can anyone help me in translating this code in Swift?

Cris
  • 12,124
  • 27
  • 92
  • 159

1 Answers1

1

Without knowing anything more about the API it seems as though the function wants to return a block with no parameters that returns an ASCellNode.

func tableView(tableView: UITableView, nodeBlockForRowAtIndexPath indexPath: NSIndexPath) -> ASCellNodeBlock {

    let photoModel = photoFeed[indexPath.row]

    let cellNodeBlock:() -> AScellNode = {
        let cellNode = PhotoCellNode(photoObject: photoModel)
        return cellNode
    }

    return cellNodeBlock
}

And from the easily searchable docs...

These two methods, need to return either an ASCellNode or an ASCellNodeBlock. An ASCellNodeBlock is a block that creates a ASCellNode which can be run on a background thread. Note that ASCellNodes are used by ASTableNode, ASCollectionNode and ASPagerNode.

Warren Burton
  • 17,451
  • 3
  • 53
  • 73