publish values from the main thread の警告 14 GitHubViewModel.swift final class GitHubViewModel: ObservableObject { private let gitHubAPIClient: GitHubAPIClient private var cancellables: Set = [] @Published var searchWord = "" @Published var repositories: [GitHubRepository] = [] init(gitHubAPIClient: GitHubAPIClient) { self.gitHubAPIClient = gitHubAPIClient } func searchButtonTapped() { gitHubAPIClient .searchRepository(searchWord) // Publishing changes from background threads is not allowed; // make sure to publish values from the main thread (via operators like receive(on:)) on model updates. .sink { [weak self] in self?.repositories = $0.items } .store(in: &cancellables) } }
この理由は advance の実装内容から明らかである 101 ` ` MyTestScheduler.swift final class MyTestScheduler { func advance(by stride: SchedulerTimeType.Stride = .zero) { // 即座に指定された最終的な値まで now を進めてしまっている now = now.advanced(by: stride) var index = 0 while index < scheduled.count { let work = scheduled[index] if work.date <= now { work.action() scheduled.remove(at: index) } else { index += 1 } } } }