Swift 字节操作

Swift Version 5 Carthage compatible CocoaPods Version Badge License Badge Supported Platforms Badge

这个库包含一系列 Swift 中用于字节操作的辅助方法。它需要 Swift 5。

如果你和我一样,总是记不住应该双向右移还是三向左移才能得到你想要的位,那么这个库可能对你有所帮助。

示例

// Let's say we have an interesting 64 bit number:
let largeNumber: UInt64 = 0xF00FA00AB00BC00C

// Extracting the fifth byte, the hard way:
let fifthByte = UInt8((largeNumber >> 24) & 0xFF)

// Extracting the fifth byte using this library:
let fifthByte = bytes(largeNumber)[4]

所有可用的字节操作方法都可以在 Bytes.swift 文件中找到。BytesTests.swift 文件包含它们的使用示例。

安装

你可以使用 CocoaPods 将此库添加到你的项目中。在你的 Podfile 中使用以下内容

pod 'SwiftBytes'

将此库添加到你的项目后,你可以在你的 Swift 文件中导入它

import SwiftBytes