Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend NS_SWIFT_UI_ACTOR to ListBindable and ListSectionController #1608

Open
2 of 3 tasks
felixrosenvik opened this issue Jun 14, 2024 · 0 comments
Open
2 of 3 tasks

Comments

@felixrosenvik
Copy link

felixrosenvik commented Jun 14, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant