Skip to content

Commit 308cc5b

Browse files
committed
Implement NSArray's customMirror
1 parent 3a40ed4 commit 308cc5b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Foundation/NSArray.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,9 @@ extension NSArray : ExpressibleByArrayLiteral {
950950
}
951951

952952
extension NSArray : CustomReflectable {
953-
public var customMirror: Mirror { NSUnimplemented() }
953+
public var customMirror: Mirror {
954+
return Mirror(reflecting: Array(self))
955+
}
954956
}
955957

956958
extension NSArray : _StructTypeBridgeable {

TestFoundation/TestNSArray.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class TestNSArray : XCTestCase {
4242
("test_insertObjectsAtIndexes", test_insertObjectsAtIndexes),
4343
("test_replaceObjectsAtIndexesWithObjects", test_replaceObjectsAtIndexesWithObjects),
4444
("test_pathsMatchingExtensions", test_pathsMatchingExtensions),
45+
("test_customMirror", test_customMirror),
4546
]
4647
}
4748

@@ -793,6 +794,22 @@ class TestNSArray : XCTestCase {
793794
let match5 = paths.pathsMatchingExtensions(["..txt"])
794795
XCTAssertEqual(match5, [])
795796
}
797+
798+
func test_customMirror() {
799+
let inputArray = ["this", "is", "a", "test", "of", "copy", "with", "strings"]
800+
let array = NSArray(array: inputArray)
801+
let arrayMirror = array.customMirror
802+
dump(arrayMirror.children)
803+
804+
XCTAssertEqual(array[0] as! String, arrayMirror.descendant(0) as! String)
805+
XCTAssertEqual(array[1] as! String, arrayMirror.descendant(1) as! String)
806+
XCTAssertEqual(array[2] as! String, arrayMirror.descendant(2) as! String)
807+
XCTAssertEqual(array[3] as! String, arrayMirror.descendant(3) as! String)
808+
XCTAssertEqual(array[4] as! String, arrayMirror.descendant(4) as! String)
809+
XCTAssertEqual(array[5] as! String, arrayMirror.descendant(5) as! String)
810+
XCTAssertEqual(array[6] as! String, arrayMirror.descendant(6) as! String)
811+
XCTAssertEqual(array[7] as! String, arrayMirror.descendant(7) as! String)
812+
}
796813

797814
private func createTestFile(_ path: String, _contents: Data) -> String? {
798815
let tempDir = NSTemporaryDirectory() + "TestFoundation_Playground_" + NSUUID().uuidString + "/"

0 commit comments

Comments
 (0)