zusammengesetzte properties, newValue

This commit is contained in:
Ingo Rohlf 2025-10-20 13:48:12 +02:00
parent 7d33f7849f
commit 8313451c1c
3 changed files with 8 additions and 3 deletions

BIN
.DS_Store vendored

Binary file not shown.

View file

@ -4,14 +4,19 @@ import Playgrounds
struct Bike {
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"
let bike = Bike.trek
bike.color
var bike = Bike.trek
bike.description
bike.description = "Mein Rad"
bike.description
// write code here
}