Skip to content

Commit 2fc16a2

Browse files
authored
Merge pull request #2813 from spevans/pr_sr_12450
2 parents f89f2e6 + 3a70c2b commit 2fc16a2

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Sources/Foundation/NSStringAPI.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,9 @@ extension String {
458458
#endif
459459
}
460460

461+
public init(_ cocoaString: NSString) {
462+
self = cocoaString._storage
463+
}
461464
}
462465

463466
extension StringProtocol where Index == String.Index {

Tests/Foundation/Tests/TestNSString.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,11 @@ class TestNSString: LoopbackServerTest {
16291629
}
16301630
}
16311631

1632+
func test_initStringWithNSString() {
1633+
let ns = NSString("Test")
1634+
XCTAssertEqual(String(ns), "Test")
1635+
}
1636+
16321637
static var allTests: [(String, (TestNSString) -> () throws -> Void)] {
16331638
var tests = [
16341639
("test_initData", test_initData),
@@ -1701,6 +1706,7 @@ class TestNSString: LoopbackServerTest {
17011706
("test_fileSystemRepresentation", test_fileSystemRepresentation),
17021707
("test_enumerateSubstrings", test_enumerateSubstrings),
17031708
("test_paragraphRange", test_paragraphRange),
1709+
("test_initStringWithNSString", test_initStringWithNSString),
17041710
]
17051711

17061712
#if !os(Windows)

0 commit comments

Comments
 (0)