SwiftBytes 0.8.0

SwiftBytes 0.8.0

测试测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2021年6月
SPM支持 SPM

Stefan van den OordDapperstout 维护。



  • Dapperstout

Swift Bytes

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