Files
SideStore/Sources/SideStoreCore/Model/RefreshAttempt.swift

51 lines
1.4 KiB
Swift
Raw Normal View History

//
// RefreshAttempt.swift
// AltStore
//
// Created by Riley Testut on 7/31/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
import CoreData
@objc(RefreshAttempt)
2023-03-01 00:48:36 -05:00
public class RefreshAttempt: NSManagedObject, Fetchable {
@NSManaged public var identifier: String
@NSManaged public var date: Date
2023-03-01 00:48:36 -05:00
@NSManaged public var isSuccess: Bool
@NSManaged public var errorDescription: String?
2023-03-01 00:48:36 -05:00
override private init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) {
super.init(entity: entity, insertInto: context)
}
2023-03-01 00:48:36 -05:00
public init(identifier: String, result: Result<[String: Result<InstalledApp, Error>], Error>, context: NSManagedObjectContext) {
super.init(entity: RefreshAttempt.entity(), insertInto: context)
2023-03-01 00:48:36 -05:00
self.identifier = identifier
2023-03-01 00:48:36 -05:00
date = Date()
do {
let results = try result.get()
2023-03-01 00:48:36 -05:00
for (_, result) in results {
guard case let .failure(error) = result else { continue }
throw error
}
2023-03-01 00:48:36 -05:00
isSuccess = true
errorDescription = nil
} catch {
isSuccess = false
errorDescription = error.localizedDescription
}
}
}
2023-03-01 00:48:36 -05:00
public extension RefreshAttempt {
@nonobjc class func fetchRequest() -> NSFetchRequest<RefreshAttempt> {
NSFetchRequest<RefreshAttempt>(entityName: "RefreshAttempt")
}
}