1 // TEST_CFLAGS -framework Foundation
3 #import <Foundation/Foundation.h>
4 #import <objc/runtime.h>
5 #import <objc/objc-abi.h>
8 @interface Test : NSObject {
10 // _object is at the last optimized property offset
11 id _object __attribute__((aligned(64)));
13 @property(readonly) Class cls;
14 @property(copy) NSString *value;
15 @property(assign) id object;
21 // _object is at the last optimized property offset
22 void *_object __attribute__((aligned(64)));
27 // Question: why can't this code be automatically generated?
29 #if !__has_feature(objc_arc)
37 - (Class)cls { return objc_getProperty(self, _cmd, 0, YES); }
39 - (NSString*)value { return (NSString*) objc_getProperty(self, _cmd, offsetof(TestDefs, _value), YES); }
40 - (void)setValue:(NSString*)inValue { objc_setProperty(self, _cmd, offsetof(TestDefs, _value), inValue, YES, YES); }
42 - (id)object { return objc_getProperty(self, _cmd, offsetof(TestDefs, _object), YES); }
43 - (void)setObject:(id)inObject { objc_setProperty(self, _cmd, offsetof(TestDefs, _object), inObject, YES, NO); }
45 - (NSString *)description {
46 return [NSString stringWithFormat:@"value = %@, object = %@", self.value, self.object];
54 NSMutableString *value = [NSMutableString stringWithUTF8String:"test"];
55 id object = [NSNumber numberWithInt:11];
56 Test *t = AUTORELEASE([Test new]);
58 [value setString:@"yuck"]; // mutate the string.
59 testassert(t.value != value); // must copy, since it was mutable.
60 testassert([t.value isEqualToString:@"test"]);
62 Class testClass = [Test class];
64 testassert(testClass == cls);
66 testassert(testClass == cls);
71 // NSLog(@"t.object = %@, t.value = %@", t.object, t.value);
72 // NSLog(@"t.object = %@, t.value = %@", t.object, t.value); // second call will optimized getters.