相关疑难解决方法(0)

为什么我不能在swift中继承多个类,就像它的库类一样

我尝试通过从两个类继承来创建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)

swift

34
推荐指数
1
解决办法
3万
查看次数

标签 统计

swift ×1