Skip to content

Instantly share code, notes, and snippets.

@chrisschreiner
Last active September 26, 2015 18:17
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 chrisschreiner/d820d7c5cc4a76e20fff to your computer and use it in GitHub Desktop.
Save chrisschreiner/d820d7c5cc4a76e20fff to your computer and use it in GitHub Desktop.
// There's some function that takes an UnsafeBufferPointer
func f(ubp: UnsafeBufferPointer<UInt8>)
...
// I want to call it with NSData
let data: NSData(...)
f(UnsafeBufferPointer(start: UnsafePointer<UInt8>(data.bytes), count: data.length))
// Would I need to NSData.withUnsafeBufferPointer() to exist? (Which of course it doesn't.)
// Or is there a way to convert NSData to [UInt8] without copying the data?
// (That feels impossible, since I can't promise [UInt8] is immutable)
// I'm slowly beginning to believe my use of [UInt8] is not nearly as "Swifty" as I thought,
// and that the correct way to hold data in Swift is NSData. I seem to constantly have little
// confusing corner cases every time I try to deal with [UInt8].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment