Skip to content

Instantly share code, notes, and snippets.

@godrm
Created October 17, 2021 11:40
Show Gist options
  • Save godrm/a2bff14ed36a98aa62f934a6ad426617 to your computer and use it in GitHub Desktop.
Save godrm/a2bff14ed36a98aa62f934a6ad426617 to your computer and use it in GitHub Desktop.
Memory Dump For Swift
import Foundation
struct Memory {
@inlinable static func dump<T>(variable: inout T) {
withUnsafePointer(to: &variable) { print($0) }
}
@inlinable static func dump(with: UnsafeRawPointer) {
let address = Int(bitPattern: with)
print(String(format:"%018p", address))
}
@inlinable static func dump(object: AnyObject) {
print(Unmanaged.passUnretained(object).toOpaque())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment