Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wuftymerguftyguff/8ef60f659182f014ea899e845e79c8a8 to your computer and use it in GitHub Desktop.
Save wuftymerguftyguff/8ef60f659182f014ea899e845e79c8a8 to your computer and use it in GitHub Desktop.
Swift3 NSData extension to get a Unsafe Pointer of a generic type to the byte data
// This extension returns an unsafe pointer of the requested type to the bytes of the NSData
// It assumes you know what you are doing
// I created it to try to insulate myself from the volatility of the Swift memory access API
extension NSData {
func toUSP<T>() -> UnsafePointer<T> {
return self.bytes.assumingMemoryBound(to:T.self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment