Last active
June 7, 2024 09:58
-
-
Save iranjith4/307c72f3a4b4f30e93888f3a04f4e330 to your computer and use it in GitHub Desktop.
Parent Child call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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