Created
October 14, 2016 11:53
-
-
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 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
// 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