Swift Generic class as delegate

你说的曾经没有我的故事 提交于 2019-12-23 20:44:38

问题


I encountered a problem when using a generic class in swift as a delegate. for example i tried to use a generic NSFetchedResultsDelegate defined as:

class FetchedTableController<T:NSManagedObject> : NSFetchedResultsControllerDelegate

Inside the class i setup a NSFetchedResultsController and set the delegate to 'self'. But for some reason the delegate methods never got called. When i removed the Generic part of the class, the delegates got called as expected:

class FetchedTableController : NSFetchedResultsControllerDelegate

Is there a solution to use generic classes as delegate?


回答1:


This seems to be fixed at Xcode7. I can successfully use generic class as NSFetchedResultsControllerDelegate, UITableViewControllerDelegate etc. ... You don't even need to add the @objc prefix to the class.

However, the class has to still have some NSObject superclass.



来源:https://stackoverflow.com/questions/26324105/swift-generic-class-as-delegate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!