ios后台处理数据存储线程

来源:互联网 发布:投资域名 后悔死了 编辑:程序博客网 时间:2024/06/04 18:35

在类中,进行编辑下面的代码:

    NSLog(@"main thread begin...");

    [selfperformSelectorInBackground:@selector(doSomething:)withObject:nil];

    NSLog(@"main thread end.....");


- (void) doSomething:(id)sender

{

    NSLog(@"one thread begin..." );  

    NSAutoreleasePool *pool = [[NSAutoreleasePoolalloc] init];

    for (int i=0; i<self.StarName_Final.count; i++) {

        [self SaveToDataBase:[StarName_FinalobjectAtIndex:i]];

    }

    NSLog(@"one thread end..." );  

    [pool release];

}