#import <Foundation/Foundation.h>
#include <unistd.h>

@interface MyString : NSObject {
    NSString *str;
    NSDate *date;
    BOOL _desc_pauses;
}

@property BOOL descriptionPauses;

- (id)initWithNSString:(NSString *)string;
@end

@implementation MyString
@synthesize descriptionPauses = _desc_pauses;

- (id)initWithNSString:(NSString *)string
{
    if (self = [super init])
    {
        str = [NSString stringWithString:string];
        date = [NSDate date];
    }
    self.descriptionPauses = NO;
    return self;
}

- (void)dealloc
{
    [date release];
    [str release];
    [super dealloc];
}

- (NSString *)description
{
    if (self.descriptionPauses)
    {
        printf ("\nAbout to sleep.\n");
        usleep(100000);
    }

    return [str stringByAppendingFormat:@" with timestamp: %@", date];
}
@end

int main (int argc, char const *argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSString *str = [NSString stringWithFormat:@"Hello from '%s'", argv[0]];
    NSLog(@"NSString instance: %@", str);

    MyString *my = [[MyString alloc] initWithNSString:str];
    NSLog(@"MyString instance: %@", [my description]);

    my.descriptionPauses = YES;

    id str_id = str; // Set break point at this line.
    SEL sel = @selector(length);
    BOOL responds = [str respondsToSelector:sel];
    printf("sizeof(id) = %zu\n", sizeof(id));
    printf("sizeof(Class) = %zu\n", sizeof(Class));
    printf("sizeof(SEL) = %zu\n", sizeof(SEL));
    printf("[str length] = %zu\n", (size_t)[str length]);
    printf("str = '%s'\n", [str cStringUsingEncoding: [NSString defaultCStringEncoding]]);

    [pool release];
    return 0;
}
