Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jeremy1026

macrumors 68020
Original poster
Nov 3, 2007
2,215
1,029
I have an NSArray declared in my .h, given a property, and synthesized. I put objects into the array, then log the count (51). I later log the count and its 0. Why am I losing my array data?


Declaring the array data:
Code:
	NSString *FeedURL = @"...aURL...";
	NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:FeedURL]];
	NSURLResponse *resp = nil;
	NSError *err = nil;
	NSData *response = [NSURLConnection sendSynchronousRequest: theRequest returningResponse: &resp error: &err];
	NSString *theString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
	tempArray = [theString componentsSeparatedByString:@"<br>"];
	if (err == nil) {
		for (int i = 0; i < [tempArray count]; i++) {
			NSLog(@"%@",[tempArray objectAtIndex:i]);
		}
		NSLog(@"Connected For SHIZZLE!!!!");
	}
	else {
		NSLog(@"AHH, oops?");
		tempArray = [NSArray arrayWithObjects:@"Internet connection required", nil];
	}
	NSLog(@"temp count - %i",[tempArray count]); //returns 51

Logging the array data down the road
Code:
- (void) changeView {
	if (theIndexPath == 4) {
		[window addSubview:twitterController.view];
		NSLog(@"temp count - %i",[tempArray count]);//returns 0
	}
}
 

Jeremy1026

macrumors 68020
Original poster
Nov 3, 2007
2,215
1,029
Solved by member of another board.

I think you forgot to retain the tempArray.

If you declared a property 'tempArray' with the 'retain' attribute, you need to call - [self setTempArray] by using:

Code:
self.tempArray = ....
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.