How can I get the memory address of a value type or a custom struct in Swift?

后端 未结 3 625
一整个雨季
一整个雨季 2021-02-04 08:08

I\'m trying to gain a deeper understanding of how Swift copies value types:

The behavior you see in your code will always be as if a copy took place. Ho

3条回答
  •  既然无缘
    2021-02-04 08:42

    I'm not sure if there's a "recommended" way to do that, but one method is to use withUnsafePointer(_:_:), like this:

    var s: String = "foo"
    withUnsafePointer(&s) { NSLog("\($0)") }
    

    This printed 0x00007ffff52a011c8 on my machine.

提交回复
热议问题