3

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?

user966697
  • 271
  • 2
  • 8
  • What happens if you try FetchedTableController : GFetchedTableController, NSFetchedResultsControllerDelegate? – Lev Landau Oct 12 '14 at 14:01
  • see: [this answer](http://stackoverflow.com/questions/26097581/generic-nsoperation-subclass-loses-nsoperation-functionality/26104946#26104946) – rintaro Oct 13 '14 at 04:35
  • ok do its not possible... i did a workaround creating a second private class to receive the delegate calls. @rintaro Thanks for marking out the answer – user966697 Oct 13 '14 at 14:09

1 Answers1

0

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.

VojtaStavik
  • 2,312
  • 1
  • 18
  • 30