Search code examples
iosobjective-cxcodeswiftmpmediapickercontroller

In swift, is there a way to have UIView class also be MPMediaPickerControllerDelegate?


I am currently trying to make a music app using swift. This is my first app (not counting a couple tutorial things). I've been looking at some sample code, including Apple's addMusic example, and I have had issues with the following translation of the objective c code into swift:

class ViewController: UIViewController <MPMediaPickerControllerDelegate> {

I get the error "Cannot specialize non-generic type 'UIViewController'. Is there a way to do this that I am missing or will I need to define a separate class to be my picker delegate?

The addMusic code I was looking at is here.


Solution

  • unlike in objective-c, the subclasses and delegates are structured the same as each other with none of the "<>" around them. For example:

    class ViewController: UIViewController, MPMediaPickerControllerDelegate, UITableViewDelegate, CustomClassDelegate
    

    You can continually add to the list as you go along, though only one of them can be the superclass (the rest must be delegates or similar) as a class cannot be the subclass of two different parent classes at the same time.

    Hope that helps.