Skip to content

Extend NS_SWIFT_UI_ACTOR to ListBindable and ListSectionController #1608

@felixrosenvik

Description

@felixrosenvik

New issue checklist

  • I have reviewed the README and documentation
  • I have searched existing issues and this is not a duplicate
  • I have attempted to reproduce the issue and include an example project.

General information

  • IGListKit version: 5.0.0
  • iOS version(s): All
  • CocoaPods/Carthage version:
  • Xcode version: 15.3
  • Devices/Simulators affected: All
  • Reproducible in the demo project? (Yes/No): Yes
  • Related issues:

Debug information

IGListKit recently added NS_SWIFT_UI_ACTOR to IGListAdapterDataSource and IGListSingleSectionControllerDelegate in this commit which is great, and helps remove many Swift Concurrency warnings. There are a couple more classes / protocols that could benefit from the same treatment.


  • UICollectionViewCell is unable to conform to ListBindable due to "Main actor-isolated instance method 'bindViewModel' cannot be used to satisfy nonisolated protocol requirement". Doing a nonisolated implementation is not a viable option, as this would require the cell to do something like this:
nonisolated func bindViewModel(_ viewModel: Any) {
    Task { @MainActor in
        /* 
            Cell will be populated asynchronously, which could cause a flicker, 
            or break unit tests that expect the cell to be populated immediately.
        */
        titleLabel.text = viewModel.title
    }
}
  • Subclassing ListSectionController is similarly problematic, as the functions it provides are currently non-isolated, but most of them will require calling UIKit, which is @MainActor isolated.
override func cellForItem(at index: Int) -> UICollectionViewCell {
    let cell: MyCell = collectionContext!.dequeueFromNib(for: self, index: index)
    /*
        "Main actor-isolated property 'titleLabel' can not be referenced from a non-isolated context"
    */
    cell.titleLabel.text = viewModel.title 
    return cell
}

These 2 instances are a couple examples that I spotted, but there could potentially exist more. I assume that IGListKit is underpinned by UICollectionViewDelegate/UICollectionViewDataSource which both are @MainActor/NS_SWIFT_UI_ACTOR, meaning that this addition could be quite straightforward.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions