Files
swift-mirror/test/Interpreter/SDK/Inputs/ObjCWeak/ObjCWeak.m
Joe Groff dfac9181dd Runtime: Add ObjC weak referencing support to SwiftObject.
We were missing -_tryRetain, -_isDeallocating, -allowsWeakReference and -retainWeakReference implementations on SwiftObject, so forming an ObjC weak reference to a pure Swift object always failed and produced a nil reference. Fixes rdar://problem/18637774.

This can be reapplied now that we properly call objc_destructInstance on deallocation.

Swift SVN r23070
2014-11-02 21:03:21 +00:00

33 lines
568 B
Objective-C

#include "ObjCWeak.h"
void tryWeakReferencing(id (^makeThing)(void)) {
id thingy;
@autoreleasepool {
thingy = makeThing();
}
__weak id weakThingy = thingy;
@autoreleasepool {
NSLog(@"before giving up strong reference:");
id x = weakThingy;
if (x) {
NSLog(@"%@", [x description]);
} else {
NSLog(@"Gone");
}
}
thingy = nil;
@autoreleasepool {
NSLog(@"after giving up strong reference:");
id x = weakThingy;
if (x) {
NSLog(@"%@", [x description]);
} else {
NSLog(@"Gone");
}
}
}