# OC使用Runloop开启常驻线程的方法

**URL:** <https://www.shiqidu.com/t/topic/539>\
**Category:** 开发调优\
**Tags:** C-C-Obj-C\
**Created:** [2019 年1 月 7 日 08:30 UTC](https://www.shiqidu.com/t/topic/539 "2019-01-07T08:30:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![Leon](https://www.shiqidu.com/user_avatar/www.shiqidu.com/leon/32/5_2.png) [@Leon](https://www.shiqidu.com/u/Leon)\
发布日期： [2019 年1 月 7 日 08:30 UTC](https://www.shiqidu.com/t/topic/539/1 "2019-01-07T08:30:22Z")

</div>

```oc
// 常驻线程(子线程开启)
- (void)foreverThead
{
    NSLog(@"%@", [NSThread currentThread]);
    // 创建runloop
    NSRunLoop *runloop = [NSRunLoop currentRunLoop];
    // 添加source
    [runloop addPort:[NSPort port] forMode:NSDefaultRunLoopMode];
    // 启动runloop
    [runloop run];
}

```
