IT

현재 메소드 호출의 견적 ID

lottoking 2020. 7. 17. 07:48
반응형

현재 메소드 호출의 견적 ID


현재 메소드가있는 현재 서열 ID를 인쇄하는 방법이 실행됩니까?

(objective-c 부탁합니다)


NSLog(@"%@", [NSThread currentThread]);

#include <pthread.h>
...
mach_port_t machTID = pthread_mach_thread_np(pthread_self());
NSLog(@"current thread: %x", machTID);

스위프트 3에서

print("Current thread \(Thread.current)")

스위프트에서

print("Current thread \(NSThread.currentThread())")

에서 Swift4

print ( "\ (나사 전류)")


다음과 같이 해킹 할 수 있습니다 (이것은 예쁘게 인쇄 수 있습니다).

+ (NSString *)getPrettyCurrentThreadDescription {
    NSString *raw = [NSString stringWithFormat:@"%@", [NSThread currentThread]];

    NSArray *firstSplit = [raw componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"{"]];
    if ([firstSplit count] > 1) {
        NSArray *secondSplit     = [firstSplit[1] componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"}"]];
        if ([secondSplit count] > 0) {
            NSString *numberAndName = secondSplit[0];
            return numberAndName;
        }
    }

    return raw;
}

참고 URL : https://stackoverflow.com/questions/1616572/getting-thread-id-of-current-method-call

반응형