mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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
33 lines
568 B
Objective-C
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");
|
|
}
|
|
}
|
|
}
|