NSThread with _NSAutoreleaseNoPool error

前端 未结 5 599
独厮守ぢ
独厮守ぢ 2021-02-04 09:38

I have an method which save files to the internet, it works but just slow. Then I\'d like to make the user interface more smooth, so I create an NSThread to handle the slow task

5条回答
  •  心在旅途
    2021-02-04 10:38

    You may need to create a run loop. I will add to Louis's solution:

    BOOL done = NO;
    
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [NSRunLoop currentRunLoop];
    
    // Start the HTTP connection here. When it's completed,
    // you could stop the run loop and then the thread will end.
    
    do {
        SInt32 result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, YES);
        if ((result == kCFRunLoopRunStopped) || (result == kCFRunLoopRunFinished)) {
            done = YES;
        }
    } while (!done);
    
    [pool release];
    

提交回复
热议问题