Schedule-ICTIS/Schedule ICTIS/ViewModel/SearchGroupsViewModel.swift
Vladimir Dubovik 15fbe5895c Commit
2025-03-13 09:24:50 +03:00

37 lines
982 B
Swift

//
// SearchGroupsViewModel.swift
// Schedule ICTIS
//
// Created by G412 on 06.03.2025.
//
import Foundation
@MainActor
final class SearchGroupsViewModel: ObservableObject {
@Published var groups: [Choice] = []
func fetchGroups(group: String) {
Task {
do {
var groups: Welcome
groups = try await NetworkManager.shared.getGroups(group: group)
self.groups = groups.choices
}
catch {
if let error = error as? NetworkError {
switch (error) {
case .invalidData:
self.groups.removeAll()
default:
self.groups.removeAll()
print("Неизвестная ошибка: \(error)")
}
print("Есть ошибка: \(error)")
}
}
}
}
}