1 | #import <Foundation/Foundation.h> |
2 | #include <iostream> |
3 | |
4 | @interface MyString : NSObject { |
5 | NSString *_string; |
6 | NSDate *_date; |
7 | } |
8 | - (id)initWithNSString:(NSString *)string; |
9 | |
10 | @property (copy) NSString *string; |
11 | @property (readonly,getter=getTheDate) NSDate *date; |
12 | |
13 | - (NSDate *) getTheDate; |
14 | @end |
15 | |
16 | @implementation MyString |
17 | |
18 | @synthesize string = _string; |
19 | @synthesize date = _date; |
20 | |
21 | - (id)initWithNSString:(NSString *)string |
22 | { |
23 | if (self = [super init]) |
24 | { |
25 | _string = [NSString stringWithString:string]; |
26 | _date = [NSDate date]; |
27 | } |
28 | return self; |
29 | } |
30 | |
31 | - (void) dealloc |
32 | { |
33 | [_date release]; |
34 | [_string release]; |
35 | [super dealloc]; |
36 | } |
37 | |
38 | - (NSDate *) getTheDate |
39 | { |
40 | return _date; |
41 | } |
42 | |
43 | - (NSString *)description |
44 | { |
45 | return [_string stringByAppendingFormat:@" with timestamp: %@" , _date]; |
46 | } |
47 | @end |
48 | |
49 | int main (int argc, char const *argv[]) |
50 | { |
51 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; |
52 | static NSString *g_global_nsstr = @"Howdy" ; |
53 | |
54 | MyString *myStr = [[MyString alloc] initWithNSString: [NSString stringWithFormat:@"string %i" , 1]]; |
55 | NSString *str1 = myStr.string; |
56 | NSString *str2 = [NSString stringWithFormat:@"string %i" , 2]; |
57 | NSString *str3 = [NSString stringWithFormat:@"string %i" , 3]; |
58 | NSArray *array = [NSArray arrayWithObjects: str1, str2, str3, nil]; |
59 | NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: |
60 | str1, @"1" , |
61 | str2, @"2" , |
62 | str3, @"3" , |
63 | myStr.date, @"date" , |
64 | nil]; |
65 | |
66 | id str_id = str1; |
67 | SEL sel = @selector(length); |
68 | [pool release]; |
69 | std::cout << "Hello, objc++!\n" ; |
70 | return 0; |
71 | } |
72 | |