Avatar
omochimetaru 9/3/2021 4:58 AM
@swift-main @swift-5.4.3 @swift-5.3.3 @swift-5.2.5 protocol P { func foo() } struct S: P { func foo() {} } func nopConsumeP(_ p: P) {} func useAny(_ x: Any) { if let p = x as? P { nopConsumeP(p) } else { print("キャスト失敗!") } } func useOptionalS(_ x: S?) { useAny(x as Any) } useOptionalS(S())