我试图通过继承两个类来创建myPet,但错误如下:
import UIKit
class SecondViewController: UIViewController, UITextFieldDelegate {
// No Error
}然后定义以下类,然后创建新的类myPets,我希望继承Dog和Substance。但是错误:从类'Dog‘和'Substance’多重继承
class Dog:Animal {
func sound()->String {
return "Hong Hong"
}
}
class Substance {
func livingCompound()->String {
return "Consist of bio-molecule"
}
}
class myPets:Dog, Substance {
func itsAddress()->String {
// Error:Multiple inheritance from classes 'Dog' and 'Substance'
}
}发布于 2014-09-01 03:32:38
Swift不支持多重继承,在这里遵循目标C。这不是从两个类继承的:
class SecondViewController: UIViewController, UITextFieldDelegate它继承了一个类UIViewController,并采用了UITextFieldDelegate协议。在https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html上阅读协议
https://stackoverflow.com/questions/25595506
复制相似问题