Can I assign my own "thread names" in Xcode?

If you can get a reference to the thread whose name you want to change, you can change it in the debugger console. Two ways to do that for the current thread:

  • (lldb) po [[NSThread currentThread] setName:@"foo"]

  • (lldb) expression (void)[(NSThread*)[NSThread currentThread] setName:@"foo"];

I'd guess you could do the same from a breakpoint that has an associated expression. If you have a method that you know will run in the thread that you're interested in, you could set a breakpoint containing one of the above commands and have it automatically continue after running the command. That'd have the effect of automatically setting the name of the thread every time you run the code, which might be handy for debugging.


Probably not exactly what you want but NSThread has setName: method that allows you to set thread's name, you can attach meaningful name to the thread so you'll get the following in debugger:

[[NSThread mainThread] setName:@"That is main thread!"];

enter image description here

Remember also that some apis (like grand central dispatch) operate with thread pools so you are not guaranteed on what thread your operation will be performed

Edit: com.apple.main-thread, com.apple.libdispatch-manager etc are labels of corresponding dispatch queues. You can set label value when queue is created with dispatch_queue_create function and later get it from the queue using dispatch_queue_get_label function.

It seems there's no API to change label value of the existing dispatch queue and I would not advise to change labels of the system queues anyway.


I use the following code in Swift 5 to rename the current thread:

    pthread_setname_np("myThreadName")