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
|
// https://carrascomolina.com
|
||||||
import Playgrounds
|
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 name: String
|
||||||
var color: String
|
var color: String
|
||||||
// newValue ist ein special keyword
|
// newValue ist ein special keyword
|
||||||
|
|
@ -14,9 +30,10 @@ struct Bike {
|
||||||
#Playground {
|
#Playground {
|
||||||
var greeting = "Hallo Playground"
|
var greeting = "Hallo Playground"
|
||||||
var bike = Bike.trek
|
var bike = Bike.trek
|
||||||
|
var train = Train(name:"TGV")
|
||||||
bike.description
|
bike.description
|
||||||
bike.description = "Mein Rad"
|
bike.description = "Mein Rad"
|
||||||
bike.description
|
bike.description
|
||||||
|
train
|
||||||
// write code here
|
// write code here
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in a new issue