That number is actually an ivar in NSThread's private implementation class. The class is _NSThreadInternal
, and its name is "_private". Inside that object, the ivar is seqNum
.
You can pull it directly if you're willing to rely on undocumented key paths. This'll do it (and good call neilsbot on using valueForKeyPath instead of runtime calls):
@implementation NSThread (GetSequenceNumber)
- (NSInteger)sequenceNumber
{
return [[self valueForKeyPath:@"private.seqNum"] integerValue];
}
@end
I tested it by manually setting that ivar with runtime calls and then NSLogging the thread. Sure enough, the description reflected the change. This is obviously not documented, so...
...use at your own risk.
It's a fun exercise, but things are typically private for a reason. Shipped code should certainly avoid things like this unless all other routes have been thoroughly exhausted.