Post

Replies

Boosts

Views

Activity

How to adapt RunLoop to swift concurrency(async/await)
I'm having some compilation warnings using Xcode 14.2/swift 5.7 (future errors in swift 6). I've some async function tests in a unit test target which include some code to process UI changes in the main loop. There are two related warnings: RunLoop.current.run(until: Date()) // which raises next warning Class property 'current' is unavailable from asynchronous contexts; currentRunLoop cannot be used from async contexts.; this is an error in Swift 6 CFRunLoopRunInMode(CFRunLoopMode.defaultMode, 0.1, false) // which raises next warning Global function 'CFRunLoopRunInMode' is unavailable from asynchronous contexts; CFRunLoopRunInMode cannot be used from async contexts.; this is an error in Swift 6 Here a full function test example. @MainActor func testBasic() async throws { // GIVEN sut = MainViewController(nibName: nil, bundle: nil) present(viewController: sut) // WHEN sut.loadViewIfNeeded() sut.showLoading() RunLoop.current.run(until: Date()) sut.hideLoading() sut.showNoConnection() RunLoop.current.run(until: Date()) // THEN XCTAssertTrue(sut.connectionStatus.isHidden == false) } What alternatives would you use at this point to fix the warnings?
4
1
2.9k
Dec ’22