brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · bb87d67 Raw
68 lines · plain
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@end13 14@implementation MyString15- (id)initWithNSString:(NSString *)string16{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)isValid27{28    return _is_valid;29}30 31- (void)dealloc32{33    [date release];34    [str release];35    [super dealloc];36}37 38- (NSString *)description39{40    return [str stringByAppendingFormat:@" with timestamp: %@", date];41}42@end43 44void45Test_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