NSThread小笔记

注意点:在自己生成的线程里面要自己管理内存,其余应该是比较简单的,thread priorities的范围是0-1的小数,1的优先级最高,dictionary可以用来存放一些信息,比如在Foundation框架里面使用这个字典来存放NSConnection和NSAssertionHandler的实例

写个小demo

- (void)viewDidLoad

{

    [superviewDidLoad];

    NSNumber *oneNumb = [NSNumber numberWithInt:1];

    NSThread *one = [[NSThreadalloc] initWithTarget:self

                                            selector:@selector(oneMethod:)

                                              object:oneNumb];

    [one start];

  [one setThreadPriority:0.8];

    NSLog(@"one == %f", [one threadPriority]);

}

-(void)oneMethod:(NSNumber *)num

{

    @autoreleasepool {

//        [NSThread sleepForTimeInterval:3];

//        NSLog(@"-------exit");

//        [NSThread exit];

        NSLog(@"-------one = %d", [num intValue]);

        if (![[NSThreadcurrentThread] isMainThread]) {

            NSLog(@"-------sub thread");

        }

        ;

        NSLog(@" addreass ----  %@ ------num = %d",     [[NSThreadcallStackReturnAddresses] objectAtIndex:0],[[NSThreadcallStackReturnAddresses] count]);

    }

}

  

上一篇:WebStrom 多项目展示及vuejs插件安装


下一篇:关于IOS的屏幕适配(iPhone)——资源适配