Avatar
norio_nomura 7/24/2018 9:35 AM
ほう。 @swift-4.2.4 @swift-main import Foundation protocol Protocol : class { func noop() } class SwiftClassBase : Protocol { func noop() { print("noop") } } class SwiftClass : SwiftClassBase { override init() { print("SwiftClass Created") } deinit { print("SwiftClass Destroyed") } } func printState(_ x : SwiftClassBase?) { print((x != nil) ? "is present" : "is nil") } func testSwiftClass() { print("testSwiftClass") // CHECK: testSwiftClass unowned var w : SwiftClassBase? printState(w) // CHECK-NEXT: is nil var c : SwiftClassBase = SwiftClass() // CHECK: SwiftClass Created printState(w) // CHECK-NEXT: is nil w = c printState(w) // CHECK-NEXT: is present c.noop() // CHECK-NEXT: noop c = SwiftClassBase() // CHECK-NEXT: SwiftClass Destroyed } testSwiftClass()