A.Jam A.Jam - 1 month ago 5
Swift Question

Can a child view controller be the delegate of its parent view controller?

Lets say there are two classes, class A and class B. Class B is a child view controller of A.

protocol ClassADelegate: class{
functions
}
class A {
code
add B as child view controller
}


protocol ClassBDelegate: class{
functions
}
class B {
code
}


Considering that class A is the parent view controller of B, My question is if class A is a delegate of class B and class B is a delegate of class A, does that create an ownership cycle? Is this bad practice?

Edit:

enter image description here

So basically I want to update the table view when the segmented control value changes and update map when a table view cell is selected. I might be wrong but I thought the best way to do this would be delegation.

Answer

The parent should be the child's delegate.

The parent, if it needs to tell the child something, should just invoke methods.