diff --git a/Tests/LibraryRefreshViewModelTest.swift b/Tests/LibraryRefreshViewModelTest.swift index ef3c388f..9592cdd1 100644 --- a/Tests/LibraryRefreshViewModelTest.swift +++ b/Tests/LibraryRefreshViewModelTest.swift @@ -21,12 +21,14 @@ import Combine @testable import Kiwix private class HTTPTestingURLProtocol: URLProtocol { + @MainActor static var handler: ((URLProtocol) -> Void)? override class func canInit(with request: URLRequest) -> Bool { true } override class func canonicalRequest(for request: URLRequest) -> URLRequest { request } override func stopLoading() { } + @MainActor override func startLoading() { if let handler = HTTPTestingURLProtocol.handler { handler(self) @@ -37,9 +39,10 @@ private class HTTPTestingURLProtocol: URLProtocol { } final class LibraryRefreshViewModelTest: XCTestCase { - private var urlSession: URLSession? + private var urlSession: URLSession! private var cancellables = Set() + @MainActor override func setUpWithError() throws { let config = URLSessionConfiguration.ephemeral config.protocolClasses = [HTTPTestingURLProtocol.self] @@ -57,6 +60,7 @@ final class LibraryRefreshViewModelTest: XCTestCase { } } + @MainActor override func tearDownWithError() throws { HTTPTestingURLProtocol.handler = nil } diff --git a/ViewModel/LibraryViewModel.swift b/ViewModel/LibraryViewModel.swift index 20e251b7..d91b8ab4 100644 --- a/ViewModel/LibraryViewModel.swift +++ b/ViewModel/LibraryViewModel.swift @@ -103,12 +103,12 @@ final class LibraryViewModel: ObservableObject { @MainActor init( - urlSession: URLSession? = nil, + urlSession: URLSession = URLSession.shared, processFactory: @MainActor () -> LibraryProcess = { .shared }, defaults: Defaulting = UDefaults(), categories: CategoriesProtocol = CategoriesToLanguages(withDefaults: UDefaults()) ) { - self.urlSession = urlSession ?? URLSession.shared + self.urlSession = urlSession self.process = processFactory() self.defaults = defaults self.categories = categories diff --git a/Views/BuildingBlocks/ZimFileCell.swift b/Views/BuildingBlocks/ZimFileCell.swift index ab37a5a6..64e7515e 100644 --- a/Views/BuildingBlocks/ZimFileCell.swift +++ b/Views/BuildingBlocks/ZimFileCell.swift @@ -17,7 +17,7 @@ import CoreData import SwiftUI struct ZimFileCell: View { - @ObservedObject var zimFile: ZimFile + @MainActor @ObservedObject var zimFile: ZimFile @State private var isHovering: Bool = false let isLoading: Bool let isSelected: Bool