我尝试通过从两个类继承来创建myPet,但错误例如:
import UIKit
class SecondViewController: UIViewController, UITextFieldDelegate {
// No Error
}
Run Code Online (Sandbox Code Playgroud)
然后定义了以下类,然后创建新类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'
}
}
Run Code Online (Sandbox Code Playgroud)
Woj*_*wka 64
Swift不支持多重继承,遵循目标C.这不是两个类的继承:
class SecondViewController: UIViewController, UITextFieldDelegate
Run Code Online (Sandbox Code Playgroud)
它是从一个类继承UIViewController并采用UITextFieldDelegate协议.有关协议的信息,请访问https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html
| 归档时间: |
|
| 查看次数: |
30467 次 |
| 最近记录: |