Last active
October 30, 2016 05:48
-
-
Save pofat/f913ed324fc6a1967d22ef361709fa43 to your computer and use it in GitHub Desktop.
Print struct address in Swift 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get array address | |
func getBufferAddress<T>(of array: [T]) -> String { | |
return array.withUnsafeBufferPointer { buffer in | |
return String(describing: buffer.baseAddress) | |
} | |
} | |
// Realize copy-on-write | |
var fiverInts = [1,2,3,4,5] | |
let copyFive = fiverInts | |
print(getBufferAddress(of: fiverInts)) | |
print(getBufferAddress(of: copyFive)) | |
fiverInts.append(6) | |
print(getBufferAddress(of: fiverInts)) | |
print(getBufferAddress(of: copyFive)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment