Schulung_iOS/SwapperView.swift
2025-10-22 08:19:25 +02:00

47 lines
813 B
Swift

import SwiftUI
struct SwapperView: TabContent {
static var title = "Swap"
static var image = "rectangle.2.swap"
@State var sw = Swapper(a: "Apfel", b: "Banana")
@State var a = "Apfel"
@State var b = "Banane"
func tausche(){
let tmp = a
a = b
b = tmp
}
var body: some View {
VStack {
Text("Vorher \(a) <-> \(b)")
Button("Show Alert") {
print("Hello, World!")
tausche()
sw.tausche()
}
Text("Swapping \(sw.a) <-> \(sw.b)")
}
}
}
struct Swapper<T> {
var a: T
var b: T
mutating func tausche(){
let tmp = a
a = b
b = tmp
}
}
#Preview {
SwapperView()
}