diff --git a/Foundation/Thread.swift b/Foundation/Thread.swift index a86854ed3e..bd9556e624 100644 --- a/Foundation/Thread.swift +++ b/Foundation/Thread.swift @@ -251,9 +251,12 @@ open class Thread : NSObject { } open var name: String? { - didSet { + get { + return _name + } + set { if let thread = _thread { - _CFThreadSetName(thread, name ?? "" ) + _CFThreadSetName(thread, newValue ?? "" ) } } } diff --git a/TestFoundation/TestThread.swift b/TestFoundation/TestThread.swift index 05a0c30dee..96a45e0662 100644 --- a/TestFoundation/TestThread.swift +++ b/TestFoundation/TestThread.swift @@ -68,16 +68,17 @@ class TestThread : XCTestCase { #if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT func test_threadName() { - // No name is set initially - XCTAssertNil(Thread.current.name) - #if os(Linux) // Linux sets the initial thread name to the process name. + XCTAssertEqual(Thread.current.name, "TestFoundation") XCTAssertEqual(Thread.current._name, "TestFoundation") #else + // No name is set initially + XCTAssertEqual(Thread.current.name, "") XCTAssertEqual(Thread.current._name, "") #endif Thread.current.name = "mainThread" XCTAssertEqual(Thread.mainThread.name, "mainThread") + XCTAssertEqual(Thread.mainThread._name, "mainThread") let condition = NSCondition() condition.lock()