forked from mikeash/MAObject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester.m
98 lines (76 loc) · 2.27 KB
/
tester.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// clang -framework Foundation MAObject.m tester.m
#import "MAObject.h"
//#import <Foundation/Foundation.h>
@interface TestObject : MAObject
@end
@implementation TestObject {
int a;
char b;
float c;
double d;
id e;
long long f;
NSMutableDictionary *g;
id _h;
}
- (void)dealloc
{
NSLog(@"Dealloc!");
[super dealloc];
}
- (void)setFoo: (id)value
{
NSLog(@"setFoo: %@", value);
}
- (void)setBar: (int)value
{
NSLog(@"setBar: %d", value);
}
- (void)setBaz: (double)value
{
NSLog(@"setBaz: %f", value);
}
- (id)foo
{
return @"foovalue";
}
- (int)bar
{
return 42;
}
- (double)baz
{
return 99.99;
}
@end
int main(int argc, char **argv)
{
@autoreleasepool
{
// Method *methods = class_copyMethodList([NSObject class], NULL);
// while(*methods++)
// NSLog(@"%s", sel_getName(method_getName(methods[-1])));
TestObject *obj = [[TestObject alloc] init];
NSLog(@"%@", obj);
[obj setValue: @1 forKey: @"a"];
[obj setValue: @2 forKey: @"b"];
[obj setValue: @3 forKey: @"c"];
[obj setValue: @4 forKey: @"d"];
[obj setValue: @"five" forKey: @"e"];
[obj setValue: @6 forKey: @"f"];
NSLog(@"%@ %@ %@ %@ %@ %@ %@", [obj valueForKey: @"isa"], [obj valueForKey: @"a"], [obj valueForKey: @"b"], [obj valueForKey: @"c"], [obj valueForKey: @"d"], [obj valueForKey: @"e"], [obj valueForKey: @"f"]);
[obj setValue: @"something" forKey: @"foo"];
[obj setValue: @1000 forKey: @"bar"];
[obj setValue: @82.8 forKey: @"baz"];
NSLog(@"%@ %@ %@", [obj valueForKey: @"foo"], [obj valueForKey: @"bar"], [obj valueForKey: @"baz"]);
[obj setValue: [NSMutableDictionary dictionary] forKeyPath: @"g"];
[obj setValue: @2 forKeyPath: @"g.foo"];
[obj setValue: @3 forKeyPath: @"g.bar"];
NSLog(@"%@ %@ %@ %@", [obj valueForKeyPath: @"g"], [obj valueForKeyPath: @"g.foo"], [obj valueForKeyPath: @"g.bar"], [obj valueForKeyPath: @"g.baz"]);
[obj setValue: @"underscore" forKey: @"h"];
NSLog(@"%@", [obj valueForKey: @"h"]);
[obj valueForKey: @"blahblah"];
[obj release];
// [[[MAObject alloc] init] copy];
}
}