开发者

Need to use NSOperationQueue to parse two different NSOperation class

Trying to parse two different URLs which has XML data.

static NSString *string1 = @"http://abc.com/a开发者_开发百科bc1.xml";
NSURLRequest *URL1 =[NSURLRequest requestWithURL:[NSURL  URLWithString:string1]];
self.URL1Connection =[[[NSURLConnection alloc] initWithRequest:URL1 delegate:self] autorelease];

static NSString *string2 = @"http://abc.com/abc2.xml";
NSURLRequest *URL2 =[NSURLRequest requestWithURL:[NSURL URLWithString:string2]];

self.URL2Connection =[[[NSURLConnection alloc] initWithRequest:URL2 delegate:self] autorelease];

I have two different NSOperation class both working independently as both have their own work to finish. I have a parseQueue which is NSOperationqueue in which I have added two different operations.

   TestOperation *testOperation = [[TestOperation alloc]                                                     
   initWithData:self.data1 delegate:self ];

    [self.parseQueue addOperation:testOperation];
   [testOperation release];   // once added to the NSOperationQueue it's retained, we don't need it anymore
   testOperation = nil;

    Test1Operation *test1Operation = [[Test1Operation alloc]        
    initWithData:self.data2];

[self.parseQueue addOperation:test1Operation];
  [test1Operation release];   // once added to the NSOperationQueue it's retained, we don't need it anymore
   test1Operation = nil;

Basically I am trying to parse the two xml data separately and want to have concurrent operations. But when the second operation gets over adding in the queue, it still looks at the first class operation. I am lost in this since I have no idea why it is still looking for the first class even after release. Can anybody throw some ideas and help me.


I figured out the answer.

Need to call each XML URL in their own respective class and call NSOperation for each call seperately. Instead of calling on application delegate method, call on viewdidload or viewdidappear method as required.

Once finished parsing, notify the main thread that the parsing is over and return the result.

Sagos

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜