protocol Vehicle
This commit is contained in:
parent
8313451c1c
commit
cd3d32a6b9
3 changed files with 19 additions and 2 deletions
BIN
.DS_Store
vendored
BIN
.DS_Store
vendored
Binary file not shown.
|
|
@ -1,7 +1,23 @@
|
|||
// https://carrascomolina.com
|
||||
import Playgrounds
|
||||
|
||||
struct Bike {
|
||||
protocol Vehicle {
|
||||
// name ist read-only
|
||||
var name: String {get}
|
||||
var color: String {get set}
|
||||
}
|
||||
|
||||
struct Train: Vehicle {
|
||||
var name: String
|
||||
var color = "white"
|
||||
}
|
||||
|
||||
struct ICE: Vehicle {
|
||||
var name = "ICE"
|
||||
var color = "white"
|
||||
}
|
||||
|
||||
struct Bike: Vehicle {
|
||||
var name: String
|
||||
var color: String
|
||||
// newValue ist ein special keyword
|
||||
|
|
@ -14,9 +30,10 @@ struct Bike {
|
|||
#Playground {
|
||||
var greeting = "Hallo Playground"
|
||||
var bike = Bike.trek
|
||||
var train = Train(name:"TGV")
|
||||
bike.description
|
||||
bike.description = "Mein Rad"
|
||||
bike.description
|
||||
|
||||
train
|
||||
// write code here
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in a new issue