问题
Is it possible to assign multiple custom classes to the same UI Element in Swift?
I have a UITextField that I need to animate with Spring(Animation library) and I also need to use some other library on the same UITextField that provides some other functionality. I usually assign the custom class in the identity inspector custom class section in the storyboard but I can't find a way to assign multiple classes. I also tried to create a new class and inherit from both of these libraries that I am trying to use but I don't think you can have multiple inheritances in Swift.
回答1:
You can't, Swift does not support multiple-inheritance. An object can implement multiple protocols but only inherit from one class.
回答2:
For sorry this is not available in Swift ( Great C++ has it ) , so you have to select anyone and go with it
回答3:
Ok, I just came up with a great idea that fits my needs perfectly but it might not apply to everyone. Since one of the libraries I was trying to use was purely for animation, I placed my UITextView inside a view, inherited the animation library for the view and inherited the other library for UITextView. Now I have both the animations working and the functionality.
来源:https://stackoverflow.com/questions/50727692/swift-assigning-multiple-classes-to-ui-element