Skip to content

Instantly share code, notes, and snippets.

@pofat
Last active October 30, 2016 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pofat/f913ed324fc6a1967d22ef361709fa43 to your computer and use it in GitHub Desktop.
Save pofat/f913ed324fc6a1967d22ef361709fa43 to your computer and use it in GitHub Desktop.
Print struct address in Swift 3
// 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