반응형
iOS 15.5, Xcode 13.31, Swift 5, UIKit 환경에서 진행했습니다.
extension Thread {
var threadName: String {
if let currentOperationQueue = OperationQueue.current?.name {
return "OperationQueue: \(currentOperationQueue)"
} else if let underlyingDispatchQueue = OperationQueue.current?.underlyingQueue?.label {
return "DispatchQueue: \(underlyingDispatchQueue)"
} else {
let name = "undefined"
return String(cString: name, encoding: .utf8) ?? Thread.current.description
}
}
}
위와 같이 extension에 threadName 속성을 추가하여 thread의 이름을 파악할 수 있다.
참조 : https://stackoverflow.com/questions/39307800/how-to-check-current-thread-in-swift-3
반응형
'iOS > 코드조각' 카테고리의 다른 글
[iOS, Swift] 코드를 수행하는 시간 구하기 (0) | 2022.11.23 |
---|---|
[iOS, Swift] 객체의 메모리 주소 찾기 (0) | 2022.11.23 |
[iOS, Swift] localized 다국어 지원(Extension) (0) | 2022.10.27 |
[iOS, Swift] 앱 내의 파일 확인하기 (FileManager) (0) | 2022.10.24 |
[iOS, Swift] 화면 세로로 고정하기 (0) | 2022.10.18 |