자식에서 부모 view로 데이터 넘기기
Delegate Pattern
Child
protocol ChildNameDelegate {
func dataChanged(str: String)
}
class ChildClass {
var delegate: ChildNameDelegate?
func whereTheChangesAreMade(data: String) {
if let del = delegate {
del.dataChanged(data)
}
}
}
Parent
class ParentClass: ChildNameDelegate {
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
guard let segueId = segue.identifier else { return }
switch segueId {
case "childSegue":
let destVC = segue.destinationViewController as! ChildClass
destVC.delegate = self
break
default:
break
}
}
func dataChanged(str: String) {
}
}