Files
swift-mirror/test/Interpreter/weak_objc.swift
Jordan Rose 8106a11dac Disallow @objc on non-ObjC-rooted classes.
These classes don't show up well in generated headers (rdar://problem/20855568),
can't actually be allocated from Objective-C (rdar://problem/17184317), and
make the story of "what is exposed to Objective-C" more complicated. Better
to just disallow them.

All classes are still "id-compatible" in that they can be converted to
AnyObject and passed to Objective-C, they secretly implement NSObjectProtocol
(via our SwiftObject root class), and their members can still be individually
exposed to Objective-C.

The frontend flag -disable-objc-attr-requires-foundation-module will disable
this requirement as well, which is still necessary for both the standard
library and a variety of tests I didn't feel like transforming.

Swift SVN r29760
2015-06-27 16:27:56 +00:00

49 lines
1.2 KiB
Swift

// RUN: %target-build-swift %s -Xfrontend -disable-objc-attr-requires-foundation-module -o %t-main
// RUN: %target-run %t-main | FileCheck %s
// REQUIRES: executable_test
// REQUIRES: objc_interop
import Foundation
protocol Protocol : class {
func noop()
}
//========================== Test ObjC classes ==========================
@objc
class ObjCClassBase : Protocol {
func noop() { print("noop") }
}
@objc
class ObjCClass : ObjCClassBase {
override init() {
print("ObjCClass Created")
}
deinit {
print("ObjCClass Destroyed")
}
}
func printState(x : ObjCClassBase?) {
print((x != nil) ? "is present" : "is nil")
}
func testObjCClass() {
print("testObjCClass") // CHECK: testObjCClass
weak var w : ObjCClassBase?
printState(w) // CHECK-NEXT: is nil
var c : ObjCClassBase = ObjCClass() // CHECK: ObjCClass Created
printState(w) // CHECK-NEXT: is nil
w = c
printState(w) // CHECK-NEXT: is present
c.noop() // CHECK-NEXT: noop
c = ObjCClassBase() // CHECK-NEXT: ObjCClass Destroyed
printState(w) // CHECK-NEXT: is nil
}
testObjCClass()