fix: Resolve Swift concurrency errors by extracting MainActor functions

Extract watchlist mutations into dedicated @MainActor functions to avoid
actor-isolated property access issues in async context. This fixes CI
build failures caused by strict concurrency checking.
This commit is contained in:
Paweł Orzech 2026-01-20 13:22:26 +00:00
parent 9724bcbacb
commit e10add9474
No known key found for this signature in database

View file

@ -300,23 +300,11 @@ class AppState: ObservableObject {
let sortedListings = allListings.sorted { $0.price < $1.price } let sortedListings = allListings.sorted { $0.price < $1.price }
logger.debug("Item \(itemId): found \(sortedListings.count) listings, lowest: \(sortedListings.first?.price ?? 0)") logger.debug("Item \(itemId): found \(sortedListings.count) listings, lowest: \(sortedListings.first?.price ?? 0)")
await MainActor.run { if let best = sortedListings.first {
if let index = watchlistItems.firstIndex(where: { $0.id == itemId }) { let secondPrice = sortedListings.count > 1 ? sortedListings[1].price : 0
if let best = sortedListings.first { await updateItemPrice(itemId: itemId, lowestPrice: best.price, lowestPriceQuantity: best.amount, secondLowestPrice: secondPrice)
var item = watchlistItems[index] } else {
item.lowestPrice = best.price await updateItemError(itemId: itemId, error: "No listings")
item.lowestPriceQuantity = best.amount
item.secondLowestPrice = sortedListings.count > 1 ? sortedListings[1].price : 0
item.lastUpdated = Date()
item.error = nil
watchlistItems[index] = item
} else {
var item = watchlistItems[index]
item.error = "No listings"
watchlistItems[index] = item
}
saveWatchlist()
}
} }
} }
} catch { } catch {
@ -325,6 +313,20 @@ class AppState: ObservableObject {
} }
} }
@MainActor
private func updateItemPrice(itemId: Int, lowestPrice: Int, lowestPriceQuantity: Int, secondLowestPrice: Int) {
if let index = watchlistItems.firstIndex(where: { $0.id == itemId }) {
var item = watchlistItems[index]
item.lowestPrice = lowestPrice
item.lowestPriceQuantity = lowestPriceQuantity
item.secondLowestPrice = secondLowestPrice
item.lastUpdated = Date()
item.error = nil
watchlistItems[index] = item
saveWatchlist()
}
}
@MainActor @MainActor
private func updateItemError(itemId: Int, error: String) { private func updateItemError(itemId: Int, error: String) {
if let index = watchlistItems.firstIndex(where: { $0.id == itemId }) { if let index = watchlistItems.firstIndex(where: { $0.id == itemId }) {