Note that there are some explanatory texts on larger screens.

plurals
  1. PONSInvocationOperation to call method that downloads XML file to store locally
    primarykey
    data
    text
    <p>new to the Objective-C/iOS scene. Experienced in PHP and C++.</p> <p>I'm having a little trouble using NSInvocationOperation. Here's my situation:</p> <p>With some help online, I've a class, getData.h where getData.m contains:</p> <pre><code>#import "getData.h" @implementation getData @synthesize allData; -(void)loadData{ NSOperationQueue *queue = [NSOperationQueue new]; NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(getXML) object:nil]; [queue addOperation:operation]; [operation release]; } -(void)getXML{ NSURL *url = [NSURL URLWithString:@"http://tubeupdates.com/rss/all.xml"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [NSURLConnection connectionWithRequest:request delegate:self]; NSError *requestError; NSURLResponse *urlResponse = nil; NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;urlResponse error:&amp;requestError]; if (response == nil) { // Check for problems if (requestError != nil) { NSLog(@"Error!"); } } } -(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { if (allData) [allData appendData:data]; else allData = [[NSMutableData alloc] initWithData:data]; } -(void) connectionDidFinishLoading:(NSURLConnection *)connection { NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *fullName = [NSString stringWithFormat:@"feed.xml"]; NSString *fullFilePath = [NSString stringWithFormat:@"%@/%@",docDir,fullName]; [allData writeToFile:fullFilePath atomically:YES]; } -(void)dealloc{ [allData release]; [super dealloc]; } @end </code></pre> <p>I know that the method is being called into the queue as I had made a temporary "printthis" method for it to call which simply displayed some text with NSLog. However my issue arises when trying to call the getXML function (to copy the XML file from the server). getXML works if I call it directly, but doesn't when I add it to the Queue. It's very likely that I'm missing the bigger picture and that I haven't fully understood everything before I've started. I would appreciate some help on this. It seems no matter how good you are at C++, PHP etc, iOS Programming is a tough one!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload