Avatar
Avatar
ジュニア
@swift-5.10.1 protocol P { mutating func mutatingFunc1() mutating func mutatingFunc2() func nonMutatingFunc() } extension P { mutating func mutatingFunc1() { print("mutatingFunc1 of P") } func mutatingFunc2() { print("mutatingFunc2 of P") } func nonMutatingFunc() { print("nonMutatingFunc of P") } } struct S: P { mutating func mutatingFunc1() { print("mutatingFunc1 of S") } mutating func mutatingFunc2() { print("mutatingFunc2 of S") } func nonMutatingFunc() { print("nonMutatingFunc of S") } } func useP(_ p: some P) { p.mutatingFunc2() p.nonMutatingFunc() } func useMutableP(_ p: inout some P) { p.mutatingFunc1() p.mutatingFunc2() p.nonMutatingFunc() } var s = S() print("--- useP ---") useP(s) print("--- useMutableP ---") useMutableP(&s)
swift510 BOT 4/20/2024 5:27 PM
--- useP --- mutatingFunc2 of P nonMutatingFunc of S --- useMutableP --- mutatingFunc1 of S mutatingFunc2 of S nonMutatingFunc of S