mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
NSLog does additional things like writing to the system log; this test doesn't need that.
35 lines
686 B
Objective-C
35 lines
686 B
Objective-C
#include "ObjCWeak.h"
|
|
|
|
void tryWeakReferencing(id (^makeThing)(void)) {
|
|
id thingy;
|
|
@autoreleasepool {
|
|
thingy = makeThing();
|
|
}
|
|
|
|
__weak id weakThingy = thingy;
|
|
|
|
@autoreleasepool {
|
|
fputs("before giving up strong reference:\n", stderr);
|
|
id x = weakThingy;
|
|
if (x) {
|
|
fputs([[x description] UTF8String], stderr);
|
|
fputs("\n", stderr);
|
|
} else {
|
|
fputs("Gone\n", stderr);
|
|
}
|
|
}
|
|
|
|
thingy = nil;
|
|
|
|
@autoreleasepool {
|
|
fputs("after giving up strong reference:\n", stderr);
|
|
id x = weakThingy;
|
|
if (x) {
|
|
fputs([[x description] UTF8String], stderr);
|
|
fputs("\n", stderr);
|
|
} else {
|
|
fputs("Gone\n", stderr);
|
|
}
|
|
}
|
|
}
|