Printing a variable memory address in swift

前端 未结 15 1042
天涯浪人
天涯浪人 2020-11-28 01:16

Is there anyway to simulate the [NSString stringWithFormat:@\"%p\", myVar], from Objective-C, in the new Swift language?

For example:

le         


        
15条回答
  •  清酒与你
    2020-11-28 01:45

    In Swift4 about Array:

        let array1 = [1,2,3]
        let array2 = array1
        array1.withUnsafeBufferPointer { (point) in
            print(point) // UnsafeBufferPointer(start: 0x00006000004681e0, count: 3)
        }
        array2.withUnsafeBufferPointer { (point) in
            print(point) // UnsafeBufferPointer(start: 0x00006000004681e0, count: 3)
        }
    

提交回复
热议问题