Design pattern for sharing some code with two different classes?

时间:2015-07-28 23:21:16

标签: ios swift

I have a UITableView. I am using a class inheriting MGSwipeTableCell for my cells and I have a header which is a UIView. I have some portion of code that are pretty similar if it's not exactly the same.

I guess there is a way to write those functions once only and eventually adapt the gap for each class but I don't really know how as the classes are not of the same type.

How could I do it properly?

1 个答案:

答案 0 :(得分:0)

Look at protocols and class extensions. You can probably design a protocol the defines the methods you want to share, and then an extension that lets you add methods and properties to your classes.