是否可以将相同的方法添加到不同的类中?如何将相同的方法添加到不同的类中?
例子:
class FilterableTable: UITableViewController { ... }
class FilterableCollection: UICollectionViewController { ... }
extension FilterableTable, FilterableCollection { // I know this line is wrong
func filterItems(){ print('filtered!') }
}
如何添加相同美孚方法将UICollectionViewController
?
协议允许申报只需要签名方法,但我需要完全相同的方法(与机构),以避免复制粘贴...
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Inheritance.html – Stefan
也许你应该建立在你的_model-layer_过滤类别...不上你的_controller-layer_ - 否则当你需要的时候,你需要在你的_contoller层的任何地方复制和粘贴正文。 MVC。 MVC。 MVC。我知道这很难学,但应该是。 – holex
@holex没关系,你在想你很聪明。问题是 - 我不需要模型,而是需要它。根据型号的数据显示/更新按钮,控件等。 – norlin