Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
33
Task/Abstract-type/Swift/abstract-type.swift
Normal file
33
Task/Abstract-type/Swift/abstract-type.swift
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
protocol Pet {
|
||||
var name: String { get set }
|
||||
var favouriteToy: String { get set }
|
||||
|
||||
func feed() -> Bool
|
||||
|
||||
func stroke() -> Void
|
||||
|
||||
}
|
||||
|
||||
extension Pet {
|
||||
// Default implementation must be in an extension, not in the declaration above
|
||||
|
||||
func stroke() {
|
||||
print("default purr")
|
||||
}
|
||||
}
|
||||
|
||||
struct Dog: Pet {
|
||||
var name: String
|
||||
var favouriteToy: String
|
||||
|
||||
// Required implementation
|
||||
func feed() -> Bool {
|
||||
print("more please")
|
||||
return false
|
||||
}
|
||||
// If this were not implemented, the default from the extension above
|
||||
// would be called.
|
||||
func stroke() {
|
||||
print("roll over")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue