Search code examples
nsurlconnectionnsdatansurlrequestyahoo-finance

NSURLConnection not downloading all data


How comes when i run this code, the data that gets downloaded seems to have cropped off some information from the first row?

NSURL *url = [NSURL URLWithString:@"http://ichart.finance.yahoo.com/table.csv?   s=GOOG&d=6&e=27&f=2012&g=d&a=6&b=25&c=2011&ignore=.csv"];
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
NSURLConnection *connection= [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];

The data then gets sorted here:

NSString *strData = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding];
strData = [strData stringByReplacingOccurrencesOfString:@"Date,Open,High,Low,Close,Volume,Adj Close" withString:@""];
NSArray* arrUncleanDataLine = [strData componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
NSMutableArray *arrCleanDataLine = [[NSMutableArray alloc]init];
NSString *temp = [[NSString alloc]init];

The top line gets cropped off. Why is this? Is it because NSData can only hold a certain amount of data?


Solution

  • Because you yourself remove the first line "Date,Open,High,Low,Close,Volume,Adj Close" by this code:

    strData = [strData stringByReplacingOccurrencesOfString:@"Date,Open,High,Low,Close,Volume,Adj Close" withString:@""];
    

    So just comment this line.