Read here swift guide on closures.
class VCText: UIViewController {
...
var completionHandler: (([addCatogrey])->Void)?
...
@IBAction func doneBtnClicke(_ sender: Any) {
...
/// return a copy of the array no need to create the object already added to the array a second time as done in your code using the delegate protocol pattern
completionHandler?(arrS1)
}
}
In view controller A
...
let vc = self.storyboard?.instantiateViewController(withIdentifier: "VCText") as! VCText
vc.delgateText = self // get rid of this
/// define body of completion handler here
vc.completionHandler = { array in
/// do something with the array in view controller A
}
...
Topic:
Programming Languages
SubTopic:
Swift
Tags: