Created
August 10, 2017 22:46
-
-
Save bricklife/f4f3a7c53f31f007536655eb5e72c896 to your computer and use it in GitHub Desktop.
16進数文字列からDataを生成するやつその3。ずらしてzipして間引いてみた。Rxのbufferが欲しい #CodePiece
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
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