views:

19

answers:

1

Hi there

I don't know why I'm getting this error. I'm also getting an EXC_BAD_ACCESS issue from the following code. Any ideas why?

Running breakpoints on the didRecieveResponse and didRecieveData and didFinishLoading shows the first two get run and mid way through recieving data the program crashes.

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    // starts... :)
    plistContentsData = [NSMutableData data]; //NSMutableData - inst in head

}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [plistContentsData appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    mellowListings = [[NSArray alloc] initWithData:plistContentsData]; //NSArray - inst in head

    NSLog(@"%@",mellowListings);

    CLLocationCoordinate2D newLocation;

    int counter = 0;

    for(NSDictionary *tempDict in mellowListings){
        NSLog(@"%f",([[tempDict objectForKey:@"lat"] floatValue]));
        NSLog(@"%f",([[tempDict objectForKey:@"long"] floatValue]));
        newLocation.latitude = ([[tempDict objectForKey:@"lat"] floatValue]);
        newLocation.longitude = ([[tempDict objectForKey:@"long"] floatValue]);
        TCPlaceMarker *placemark = [[TCPlaceMarker alloc] initWithCoordinate:newLocation];
        placemark.title = [tempDict objectForKey:@"name"];
        placemark.subtitle = [tempDict objectForKey:@"address1"];
        placemark.source = [[tempDict objectForKey:@"source"] lowercaseString];
        placemark.tag = counter;
        [mapView addAnnotation:placemark];
        counter++;
    }
}
A: 
plistContentsData = [NSMutableData data];

You create an autoreleased NSMutableData object and it may become invalid right after you exit didReceiveResponse method. You need to retain plistContentsData to fix that error.

Vladimir
ah, that works. :) Thanks, erm, still getting the `invalid chunk type` error though. :( any ideas there?
Thomas Clayson
In what line(or method) do you get that error?
Vladimir
I have no idea - with breakpoints in the error doesn't occur. :/
Thomas Clayson
but is this an error (and app crashes) or just a console message? Never seen it myself and googling does not give anything relevant it seems...
Vladimir
oh i see... the app doesn't crash. and yeah, I spent hours crawling google and not finding anything. :/ its just in the console, but I don't know what it means. I guess if everything still works its fine?
Thomas Clayson
Yes, if it works you can live with it :) May be it is worth asking on official apple forums? If you find an answer let us know please
Vladimir
will do. :) thanks for your help :)
Thomas Clayson