Skip to content

Instantly share code, notes, and snippets.

@odrobnik
Created November 5, 2021 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odrobnik/03acd7d908540466b78599b89d7a14ab to your computer and use it in GitHub Desktop.
Save odrobnik/03acd7d908540466b78599b89d7a14ab to your computer and use it in GitHub Desktop.
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