Skip to content

Commit 72e4427

Browse files
authored
Merge pull request #2033 from noppefoxwolf/ImplementCustomMirror
2 parents 7e390f3 + 678a14d commit 72e4427

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Foundation/NSArray.swift

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

954954
extension NSArray : CustomReflectable {
955-
public var customMirror: Mirror { NSUnimplemented() }
955+
public var customMirror: Mirror {
956+
return Mirror(reflecting: _storage)
957+
}
956958
}
957959

958960
extension NSArray : _StructTypeBridgeable {

TestFoundation/TestNSArray.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class TestNSArray : XCTestCase {
4545
("test_replaceObjectsAtIndexesWithObjects", test_replaceObjectsAtIndexesWithObjects),
4646
("test_pathsMatchingExtensions", test_pathsMatchingExtensions),
4747
("test_arrayUsedAsCFArrayInvokesArrayMethods", test_arrayUsedAsCFArrayInvokesArrayMethods),
48+
("test_customMirror", test_customMirror),
4849
]
4950
}
5051

@@ -796,6 +797,20 @@ class TestNSArray : XCTestCase {
796797
let match5 = paths.pathsMatchingExtensions(["..txt"])
797798
XCTAssertEqual(match5, [])
798799
}
800+
801+
func test_customMirror() {
802+
let inputArray = ["this", "is", "a", "test", "of", "custom", "mirror"]
803+
let array = NSArray(array: inputArray)
804+
let arrayMirror = array.customMirror
805+
806+
XCTAssertEqual(array[0] as! String, arrayMirror.descendant(0) as! String)
807+
XCTAssertEqual(array[1] as! String, arrayMirror.descendant(1) as! String)
808+
XCTAssertEqual(array[2] as! String, arrayMirror.descendant(2) as! String)
809+
XCTAssertEqual(array[3] as! String, arrayMirror.descendant(3) as! String)
810+
XCTAssertEqual(array[4] as! String, arrayMirror.descendant(4) as! String)
811+
XCTAssertEqual(array[5] as! String, arrayMirror.descendant(5) as! String)
812+
XCTAssertEqual(array[6] as! String, arrayMirror.descendant(6) as! String)
813+
}
799814

800815
func test_arrayUsedAsCFArrayInvokesArrayMethods() {
801816
let number = 789 as NSNumber

0 commit comments

Comments
 (0)