Files
swift-mirror/test/Interpreter/SDK/Inputs/ObjCWeak/ObjCWeak.m
Jordan Rose 4968da94bf [test] Switch a test from NSLog to fputs.
NSLog does additional things like writing to the system log; this test
doesn't need that.
2016-05-12 16:18:11 -07:00

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);
}
}
}