Helperobject: methods not called


#1

Hi all,
I can’t get the connectionDidFinishingLoading method to be called

I get:

2012-08-25 05:26:56.096 callbacks[408:303] received 665331 bytes
2012-08-25 05:26:58.081 callbacks[408:303] Ouch!
2012-08-25 05:27:00.081 callbacks[408:303] Ouch!
2012-08-25 05:27:02.098 callbacks[408:303] Ouch!
2012-08-25 05:27:04.081 callbacks[408:303] Ouch!
2012-08-25 05:27:06.081 callbacks[408:303] Ouch!

Any help would be appreciated

here are my codes:


#import <Foundation/Foundation.h>

@interface Logger : NSObject

{
    NSMutableData*incomingData;
}

- (void)sayOuch:(NSTimer *)t;

@end

#import "Logger.h"

@implementation Logger


- (void)sayOuch:(NSTimer *)t;

{
    NSLog(@"Ouch!");
    
}

- (void) connection:(NSURLConnection *)connection
    didReceiveData:(NSData *)data

{
    NSLog(@"received %lu bytes", [data length]);
    
    if (!incomingData) {
        incomingData = [[NSMutableData alloc] init];
        
    }

    [incomingData appendData:data];
}
- (void)connectionDidfinishLoading:(NSURLConnection *)connection
   
   {
       NSLog(@"Got it all!");
       NSString *string = [[NSString alloc] initWithData:incomingData
                                                encoding:NSUTF8StringEncoding];
       incomingData = nil;
       NSLog(@"string has %lu characters", [string length]);
       
       NSLog(@"The whole string is %@", string);
   }
   
   - (void) connection:(NSURLConnection *)connection
                    didFailWithError:(NSError *)error
   
   {
       NSLog(@"connection failed: %@", [error localizedDescription]);
             incomingData = nil;
   }
@end

#import <Foundation/Foundation.h>
#import "Logger.h"
int main(int argc, const char * argv[])
{

    @autoreleasepool {
        
        Logger * logger = [[Logger alloc] init];
        
        NSURL *url = [NSURL URLWithString:@"http://www.gutenberg.org/cache/epub/205/pg205.txt"];
        
        
        NSURLRequest*request=[NSURLRequest requestWithURL:url];
        
        __unused NSURLConnection * fetchconn=[[NSURLConnection alloc] initWithRequest:request delegate:logger startImmediately:YES];
        
        
        __unused NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.0
                                                          target:logger
                                                        selector:@selector(sayOuch:)
                                                        userInfo:nil
                                                          repeats:YES];
        
        [[NSRunLoop currentRunLoop] run];
        
    }
    return 0;
}

#2

- (void)connectionDidfinishLoading:(NSURLConnection *)connection
should be

- (void)connectionDidFinishLoading:(NSURLConnection *)connection