Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
I assume that you need to keep the NSMutableArrays passed to parserDone:wasLoadedForURL: around until all 4 are available. Why not just check that all 4 variables you are storing these in are not nil?
 
I assume that you need to keep the NSMutableArrays passed to parserDone:wasLoadedForURL: around until all 4 are available. Why not just check that all 4 variables you are storing these in are not nil?

mmm...yes to check the arrays count not being 0 is good. Thanks for the advice! :) I am not at my MAC right now and will have to wait till tomorrow to try this out - but I have a good feeling about it ;-)
Again - thanks so far!
MACloop
 
Good morning!
So, I have tried the thoughts from yesterday and have one problem to solve. In the DataAccess class is the data variable not nil til the last delegate method connectionDidFinishLoading where I intend to write the complete data to a variable in order to send it to my delegate, as we spoke yesterday. Here is the data nil... Am I missing something here? (I have left the urlToConnection for now to isolate this problem)
Thanks in advance!
MACloop

Code:
- (id)initWithUrl:(NSURL*)_url withDelegate:(id)del{
	if(self = [super init]){
		self.theUrl = _url;
		self.status = NEW;
		self.delegate = del;
		self.theData = [NSMutableData data];
	}
	return self;
}

- (void) startLoadingURL {
	self.status = FETCHING;
	NSURLRequest *theRequest = [NSURLRequest requestWithURL:theUrl];
	myConnection = [[NSURLConnection alloc]initWithRequest:theRequest delegate:self];
	
	NSMutableData *data = [NSMutableData data];
	[connectionToData setObject:data forKey:myConnection];
	[myConnection release];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
	[theData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
	self.theData = [NSMutableData dataWithData:[connectionToData objectForKey:connection]];
	[theData appendData:data];
	NSLog([NSString stringWithFormat:@"%@", theData]);[COLOR="Red"]//theData variable is not nil here[/COLOR]
}


- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
	@synchronized(self){
		if(self.status != FAILED) {
			self.status = COMPLETE;
			NSMutableData *theDataToSend = [NSMutableData data];
			theDataToSend = [connectionToData objectForKey:connection];
			NSLog([NSString stringWithFormat:@"%@", theDataToSend]);[COLOR="Red"]//this variable is empty[/COLOR]
			[self.delegate startParsing:theDataToSend];
			theData = nil;
		}
	}
	[connectionToData removeObjectForKey:connection];
}
 
Good morning!
So, I have tried the thoughts from yesterday and have one problem to solve. In the DataAccess class is the data variable not nil til the last delegate method connectionDidFinishLoading where I intend to write the complete data to a variable in order to send it to my delegate, as we spoke yesterday. Here is the data nil... Am I missing something here? (I have left the urlToConnection for now to isolate this problem)
Thanks in advance!
MACloop

Code:
- (id)initWithUrl:(NSURL*)_url withDelegate:(id)del{
	if(self = [super init]){
		self.theUrl = _url;
		self.status = NEW;
		self.delegate = del;
		self.theData = [NSMutableData data];
	}
	return self;
}

- (void) startLoadingURL {
	self.status = FETCHING;
	NSURLRequest *theRequest = [NSURLRequest requestWithURL:theUrl];
	myConnection = [[NSURLConnection alloc]initWithRequest:theRequest delegate:self];
	
	NSMutableData *data = [NSMutableData data];
	[connectionToData setObject:data forKey:myConnection];
	[myConnection release];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
	[theData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
	self.theData = [NSMutableData dataWithData:[connectionToData objectForKey:connection]];
	[theData appendData:data];
	NSLog([NSString stringWithFormat:@"%@", theData]);[COLOR="Red"]//theData variable is not nil here[/COLOR]
}


- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
	@synchronized(self){
		if(self.status != FAILED) {
			self.status = COMPLETE;
			NSMutableData *theDataToSend = [NSMutableData data];
			theDataToSend = [connectionToData objectForKey:connection];
			NSLog([NSString stringWithFormat:@"%@", theDataToSend]);[COLOR="Red"]//this variable is empty[/COLOR]
			[self.delegate startParsing:theDataToSend];
			theData = nil;
		}
	}
	[connectionToData removeObjectForKey:connection];
}
OK, we had this problem some days ago. I am not allowed in my init to define the following.
Code:
self.connectionToData = [[NSMutableDictionary alloc]init];

I get the error msg:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURLConnection copyWithZone:]: unrecognized selector sent to instance 0x4629730'

So I suppose the problem that I cannot init my NSMutableDictionaries properly... How can I solve this? If it is not init:ed it cannot be connected with objects and keys, right? There is no other possibility for a alternative key instead of the connection, as I can see it. The connection is sent into each and every delegate method...

Strange... What can I do to solve this?
Thanks in advance!
MACloop
 
I tried a solution where I send in an array with urls into the DataAccess and every item in the array aka url is getting a number key. It seems to work.
MACloop
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.