📜  面向协议编程 swift github Basic - Swift 代码示例

📅  最后修改于: 2022-03-11 15:01:02.459000             🧑  作者: Mango

代码示例1
protocol FullName {
    var firstName: String {get set}
    var lastName: String {get set}
    
    func getFullName() -> String
}

protocol Person: FullName {
    var age: Int {get set}
}

struct Student: Person {
    var firstName = ""
    var lastName = ""
    var age = 0
    
    func getFullName() -> String {
        return "(firstName) (lastName)"
    }
}