Skip to content

Instantly share code, notes, and snippets.

@manmal
manmal / CombineHelper.swift
Created March 30, 2021 08:09 — forked from steipete/CombineHelper.swift
Combine helper that runs a Future after a delay on a background queue
import Foundation
import Combine
func runDelayedInBackground<Output, DelayingScheduler: Scheduler, ReceivingScheduler: Scheduler>(
delay: Int = 200,
scheduler: DelayingScheduler,
receiveOn: ReceivingScheduler,
worker: @escaping () -> Result<Output, Never>,
completion: @escaping (Output) -> ()
) -> AnyCancellable {
static UIView *PSPDFViewWithSuffix(UIView *view, NSString *classNameSuffix) {
if (!view || classNameSuffix.length == 0) return nil;
UIView *theView = nil;
for (__unsafe_unretained UIView *subview in view.subviews) {
if ([NSStringFromClass(subview.class) hasSuffix:classNameSuffix]) {
return subview;
}else {
if ((theView = PSPDFViewWithSuffix(subview, classNameSuffix))) break;
}