Avatar
Avatar
omochimetaru
@swift-5.10.1 @swift-6.0-dev @swift-main import Foundation public protocol AnyOptionalType { static var wrappedType: Any.Type { get } static var `nil`: Any { get } var wrappedValue: Any? { get } } public protocol OptionalType: AnyOptionalType { associatedtype Wrapped init(_ wrapped: Wrapped) } extension OptionalType { public static var wrappedType: Any.Type { return Wrapped.self } } extension Optional: OptionalType { public static var `nil`: Any { Self.none as Any } public var wrappedValue: Any? { self } } func main(x: Int?) async throws { if let x = x as? any AnyOptionalType { if case .some(let x) = x.wrappedValue { print("AnyOptionalType: \(x)") } else { print("AnyOptionalType none") } } else { print("not AnyOptionalType") } } try await main(x: nil)
swiftNightly BOT 7/2/2024 5:00 AM
AnyOptionalType none