4 #include <Foundation/NSObject.h>
5 #include <objc/runtime.h>
11 static const char *key = "key";
14 @interface Value : NSObject @end
15 @interface Super : NSObject @end
16 @interface Sub : NSObject @end
18 @interface Super2 : NSObject @end
19 @interface Sub2 : NSObject @end
24 // rdar://8270243 don't lose associations after isa swizzling
26 id value = [Value new];
27 objc_setAssociatedObject(self, &key, value, OBJC_ASSOCIATION_RETAIN);
30 object_setClass(self, [Sub class]);
61 @implementation Super2
64 // rdar://9617109 don't lose associations after isa swizzling
66 id value = [Value new];
67 object_setClass(self, [Sub2 class]);
68 objc_setAssociatedObject(self, &key, value, OBJC_ASSOCIATION_RETAIN);
70 object_setClass(self, [Super2 class]);
101 @implementation Value
117 for (i = 0; i < 100; i++) {
118 RELEASE_VALUE([[Super alloc] init]);
123 testassert(supers == 0);
124 testassert(subs > 0);
125 testassert(subs == values);
134 for (i = 0; i < 100; i++) {
135 RELEASE_VALUE([[Super2 alloc] init]);
140 testassert(supers > 0);
141 testassert(subs == 0);
142 testassert(supers == values);