Skip to content

Instantly share code, notes, and snippets.

@iranjith4
Last active June 7, 2024 09:58
Show Gist options
  • Save iranjith4/307c72f3a4b4f30e93888f3a04f4e330 to your computer and use it in GitHub Desktop.
Save iranjith4/307c72f3a4b4f30e93888f3a04f4e330 to your computer and use it in GitHub Desktop.
Parent Child call
import UIKit
import Combine
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
//let parent = Parent()
let child = Child()
let parent = child.onSuccess.send(true)
}
}
class Parent { //VisionProcessorBase
var onSuccess: PassthroughSubject<Bool, Never> = .init()
var onFailure: PassthroughSubject<Bool, Never> = .init()
func sendFromParent() {
onSuccess.send(true)
}
}
class Child: Parent { //TwistChallenge //Chile
var store = Set<AnyCancellable>() //Needed to recyle in memory
override init() {
super.init()
onSuccess.sink { value in //Value
print(value)
//Call the function in Child class
}
.store(in: &store)
onFailure.sink { value in
print(value)
}
.store(in: &store)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment