diff --git a/Sources/CustomDump/Dump.swift b/Sources/CustomDump/Dump.swift index 1041c22..bd9b7fc 100644 --- a/Sources/CustomDump/Dump.swift +++ b/Sources/CustomDump/Dump.swift @@ -59,13 +59,18 @@ public func customDump( var visitedItems: Set = [] - func customDumpHelp( - _ value: Any, + func customDumpHelp( + _ value: T, to target: inout TargetStream, name: String?, indent: Int, maxDepth: Int ) where TargetStream: TextOutputStream { + if T.self is AnyObject.Type, withUnsafeBytes(of: value, { $0.allSatisfy { $0 == 0 } }) { + target.write((name.map { "\($0): " } ?? "").appending("(null pointer)").indenting(by: indent)) + return + } + let mirror = Mirror(customDumpReflecting: value) var out = "" diff --git a/Tests/CustomDumpTests/Conformances/FoundationTests.swift b/Tests/CustomDumpTests/Conformances/FoundationTests.swift index 46ac4b6..1499cce 100644 --- a/Tests/CustomDumpTests/Conformances/FoundationTests.swift +++ b/Tests/CustomDumpTests/Conformances/FoundationTests.swift @@ -432,7 +432,7 @@ final class FoundationTests: XCTestCase { func testNSNumber() { var dump = "" customDump( - NSNumber(booleanLiteral: true), + 1 as NSNumber, to: &dump ) XCTAssertNoDifference( @@ -441,6 +441,20 @@ final class FoundationTests: XCTestCase { 1 """ ) + + #if canImport(ObjectiveC) + dump = "" + customDump( + NSNumber(), + to: &dump + ) + XCTAssertNoDifference( + dump, + """ + (null pointer) + """ + ) + #endif } func testNSOrderedSet() {