Swift concurrency compliant warning using an objc class DTGridView

20 views Asked by At

I’m attempting to convert an old project to be swift concurrency compliant. I’m using an old objc class DTGridView, and have separated out the DataSource & Delegate into MainActor classes. On compilation (SWIFT_STRICT_CONCURRENCY = complete) I see the warnings of ‘Main actor-isolated instance method ‘' cannot be used to satisfy nonisolated protocol requirement, Add 'nonisolated' to ‘' to make this instance method not isolated to the actor on the following methods in DataSource class

func numberOfRows(in gridView: DTGridView) -> Int {
var noRows: Int = 0
                let gridIdentifier = gridView.gridIdentifier
                if gridIdentifier == "HeaderEigenValues" || gridIdentifier == "HeaderEigenVectors" || gridIdentifier == "MainEigenValues" {
                    noRows = 1
                }
                else if gridIdentifier == "MainEigenVectors" || gridIdentifier == "LeftEigenVectors" {
                    noRows = 3
                }
                return noRows
}
func numberOfColumns(in gridView: DTGridView, forRowWith index: Int) -> Int
func gridView(_ gridView: DTGridView, heightForRow rowIndex: Int) -> CGFloat
func gridView(_ gridView: DTGridView, widthForCellAtRow rowIndex: Int, column columnIndex: Int) -> CGFloat
func gridView(_ gridView: DTGridView, viewForRow rowIndex: Int, column columnIndex: Int) -> DTGridViewCell!

Now this compiles and runs, however I want to prepare for swift 6, and struggling to find away to return values asynchronously in a synchronous method.

In the Delegate class, I use

nonisolated func gridView(_ gridView: DTGridView, selectionMadeAtRow rowIndex: Int, column columnIndex: Int) {
        Task {
            await clearFloatingTextField()
…
         }
}

since there is no returning value requirement, Task{} works readily.

I’ve tried to use Semaphore techniques researched from this website, in order to retrieve relevant value, but these methods get stuck in waiting for return value.

Admittedly I am just coming to terms with this new protocol, so maybe missing something fundamental. I have made a small project using UITableView in a UIController again separating out the DataSource & Delegate into @MainActor classes, compiling SWIFT_STRICT_CONCURRENCY = complete, and don’t see these nonisolated protocol requirement warnings in these 2 classes, what am I missing?

0

There are 0 answers