Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import Foundation
import Combine
import ProoficsSDK
import SwiftUI
class BundleViewModel: ObservableObject
{
@Published var title: String = ""
@Published var subtitle: String?
@Published var status: BundleStatus = .New
let url: URL?
let bundle: ProoficsSDK.Bundle
var cancellables = [AnyCancellable]()
init(bundle: ProoficsSDK.Bundle)
{
self.bundle = bundle
self.status = bundle.status
self.url = bundle.thumbnail?.url
cancellables.append(bundle.publisher(for: \.statusString).sink { newValue in
self.status = BundleStatus(rawValue: newValue)!
})
bundle.publisher(for: \.displayTitle).assign(to: &$title)
bundle.publisher(for: \.jobName).assign(to: &$subtitle)
}
}
extension BundleViewModel: Identifiable
{
var id: String
{
return bundle.objectID!
}
}
extension ProoficsSDK.Bundle
{
@objc var displayTitle: String
{
var string = ""
if let number = jobNumber
{
string += number
}
if let batch = batchNumber, !batch.isEmpty
{
string += " / Batch: " + batch
}
return string
}
@objc dynamic var statusString: String
{
get {
return status.rawValue
}
set {
status = BundleStatus(rawValue: newValue)!
}
}
}
open class Bundle: Entity
{
open var status: BundleStatus = BundleStatus.New
{
willSet
{
willChangeValue(forKey: "statusString")
}
didSet {
didChangeValue(forKey: "statusString")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment