Component evidence
Swift extensions for converting binary Data to hex strings and vice versa. Use this for data serialization, cryptography, or network protocol formatting.
// Source: https://github.com/permissionlesstech/bitchat | License: Unlicense
// Provided via justclaw.it.com; keep this notice with the code.
//
// Data+Hex.swift
// BitFoundation
//
// This is free and unencumbered software released into the public domain.
// For more information, see <https://unlicense.org>
//
import struct Foundation.Data
public extension Data {
func hexEncodedString() -> String {
if self.isEmpty {
return ""
}
return self.map { String(format: "%02x", $0) }.joined()
}
/// Initialize Data from a hex string.
/// - Parameter hexString: A hex string, optionally prefixed with "0x" or "0X".
/// Whitespace is trimmed. Must have even length after prefix removal.
/// - Returns: nil if the string has odd length or c
... (truncated -- full source via MCP)