[ad_1]
I’ve a number of steps must be processed synchronously. And the worth resulted from the method are consumed by the view. It is engaged on iOS 14, however it is crashing on iOS 13. I take advantage of a Mix to publish an occasion to replace the worth saved contained in the view mannequin.
That is the PublisherManager:
last class PublisherManager {
static let shared = PublisherManager()
non-public var cancellable = Set<AnyCancellable>()
func mainPublisher() -> AnyPublisher<MainInput, By no means> {
mainSubject
.eraseToAnyPublisher()
}
let mainSubject = PassthroughSubject<MainInput, By no means>()
enum MainInput {
case updateValue()
}
}
That is the view mannequin:
last class ViewModel: ObservableObject {
@Printed var standing: Standing = .checking
init() {
setObserver()
begin()
}
non-public func setObserver() {
PublisherManager.shared.mainPublisher()
.obtain(on: RunLoop.fundamental)
.sink { [weak self] motion in
guard let self = self else { return }
swap motion {
case .updateValue:
self.updateValue()
}
}.retailer(in: &cancellable)
}
func begin() {
let dispatchGroup = DispatchGroup()
let dispatchSemaphore = DispatchSemaphore(worth: 1)
dispatchGroup.enter()
dispatchQueue.asyncAfter(deadline: DispatchTime.now() + 1) {
dispatchSemaphore.wait()
self.getValues { //--> A course of to name API
PublisherManager.shared.pushNotificationTroubleshooterSubject.ship(.updateValue())
dispatchSemaphore.sign()
dispatchGroup.depart()
}
}
dispatchGroup.notify(queue: .fundamental) {
// Notify
}
}
non-public func updateValue() {
standing = .energetic
}
}
Once I run it, I bought EXC_BAD_ACCESS within the AppDelegate but it surely does not print any error in any respect on the debugger. If I remark the standing = .energetic code, it does not crash.
What am I doing fallacious and the way can I remedy the issue?
[ad_2]
