Schulung_iOS/Playground.swift
2025-10-20 14:04:45 +02:00

39 lines
808 B
Swift

// https://carrascomolina.com
import Playgrounds
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
var description: String {
set { name = newValue }
get {"A bike called \(name) and it is \(color)." }}
static let trek = Bike(name: "Trek", color: "red" )
}
#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
}