Skip to content

Instantly share code, notes, and snippets.

@bricklife
Created August 10, 2017 22:46
Show Gist options
  • Save bricklife/f4f3a7c53f31f007536655eb5e72c896 to your computer and use it in GitHub Desktop.
Save bricklife/f4f3a7c53f31f007536655eb5e72c896 to your computer and use it in GitHub Desktop.
16進数文字列からDataを生成するやつその3。ずらしてzipして間引いてみた。Rxのbufferが欲しい #CodePiece
let hexString = "0123456789abcdefABCDEF"
let bytes = zip(hexString.characters, hexString.characters.dropFirst())
.enumerated()
.filter { $0.offset % 2 == 0 }
.map { String([$0.element.0, $0.element.1]) }
.flatMap { UInt8($0, radix: 16) }
Data(bytes: bytes) as NSData // <01234567 89abcdef abcdef>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment