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

╄→гoц情女王★ 提交于 2019-12-25 03:53:42

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/25187306/in-swift-is-there-a-way-to-have-uiview-class-also-be-mpmediapickercontrollerdel

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