• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#import <Foundation/Foundation.h>
2#include <stdio.h>
3
4@interface MyString : NSObject {
5    NSString *str;
6    NSDate *date;
7    BOOL _is_valid;
8}
9
10- (id)initWithNSString:(NSString *)string;
11- (BOOL)isValid;
12@end
13
14@implementation MyString
15- (id)initWithNSString:(NSString *)string
16{
17    if (self = [super init])
18    {
19        str = [NSString stringWithString:string];
20        date = [NSDate date];
21    }
22    _is_valid = YES;
23    return self;
24}
25
26- (BOOL)isValid
27{
28    return _is_valid;
29}
30
31- (void)dealloc
32{
33    [date release];
34    [str release];
35    [super dealloc];
36}
37
38- (NSString *)description
39{
40    return [str stringByAppendingFormat:@" with timestamp: %@", date];
41}
42@end
43
44void
45Test_MyString (const char *program)
46{
47    NSString *str = [NSString stringWithFormat:@"Hello from '%s'", program];
48    MyString *my = [[MyString alloc] initWithNSString:str];
49    if ([my isValid])
50        printf("my is valid!\n");
51
52    NSLog(@"NSString instance: %@", [str description]); // Set breakpoint here.
53                                                        // Test 'p (int)[my isValid]'.
54                                                        // The expression parser should not crash -- rdar://problem/9691614.
55
56    NSLog(@"MyString instance: %@", [my description]);
57}
58
59int main (int argc, char const *argv[])
60{
61    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
62
63    Test_MyString (argv[0]);
64
65    [pool release];
66    return 0;
67}
68