问题
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