Minimal Swift package to decode hexadecimal strings into Data or [UInt8], with strict error handling and localized error messages.
- Convert hex strings →
Dataor[UInt8] - Clear errors for malformed input (
oddNumberOfCharacters,invalidCharacter) - Localized error descriptions for easier debugging
- Lightweight, protocol-oriented API (just extensions, no wrappers)
Add HexaDecoder to your project using Swift Package Manager:
In Package.swift:
dependencies: [
.package(url: "https://github.com/leodabus/HexaDecoder.git", from: "1.0.1")
]Or in Xcode:
File → Add Packages… → paste the repo URL https://github.com/leodabus/HexaDecoder.git.
import HexaDecoder
import Foundation
let hex = "48656c6c6f"
// Decode into Data
let data: Data = try hex.hexa()
// Decode into [UInt8]
let bytes: [UInt8] = try hex.hexa()
print(String(decoding: data, as: UTF8.self)) // "Hello"
print(bytes) // [72, 101, 108, 108, 111]do {
let _: Data = try "abc".hexa()
} catch {
print(error.localizedDescription)
// "Hex string contains an odd number of characters."
}MIT © 2025 Leonardo Dabus