Swift Generic class as delegate

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

class FetchedTableController<T:NSManagedObject> : NSFetchedResultsControllerDelegate


Inside the class, I set up NSFetchedResultsController and set the delegate to "i". But for some reason the delegate methods never got it. When I removed the generic part of the class, the delegates were called as expected:

class FetchedTableController : NSFetchedResultsControllerDelegate


Is there a solution to use generic classes as a delegate?


source to share

1 answer

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

However, the class must still have some superclass of the NSObject class.



All Articles