点击查看详细内容
线程之间通过NSPort
通讯,将NSPort
加入到runloop
中,可以通过设置port
的代理来监听该端口接受的数据,其实是先讲数据发给runloop
,然后经过runloop
中转到delegate
去处理数据。
查看具体代码
点击查看详细内容
__weak typeof(self) __weakSelf = self;
self.thread = [[FYThread alloc]initWithBlock:^{
[[NSRunLoop currentRunLoop] addPort:[NSPort port] forMode:NSDefaultRunLoopMode];
NSLog(@"%@",[NSThread currentThread]);
NSLog(@"--start--");
__weakSelf.shouldKeepRunning = YES;//默认运行
NSRunLoop *theRL = [NSRunLoop currentRunLoop];
while (__weakSelf && __weakSelf.shouldKeepRunning ){
[theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
};
NSLog(@"--end--");
}];