Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://stackoverflow.com/a/45777692/5536516
- import Foundation
- func memoryAddress(of structPointer: UnsafeMutableRawPointer) -> String {
- return structPointer.debugDescription
- }
- struct S {/* let foo = 1 */}
- var s = S()
- struct T {/* let bar = 1 */}
- var t = T()
- let m = memoryAddress(of: &s)
- let n = memoryAddress(of: &s)
- let o = memoryAddress(of: &t)
- // different addresses
- print("m = \(m)")
- print("n = \(n)")
- print("o = \(o)")
- // same addresses
- print("directly = \(memoryAddress(of: &s))")
- print("directly = \(memoryAddress(of: &s))")
- print("directly = \(memoryAddress(of: &t))")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement