String
extension String
extension String: XDRCodable
Extension providing base32 encoding and decoding for String.
Supports both standard base32 (RFC 4648) and base32hex variants.
-
Decodes a base32-encoded string to data.
Uses the standard base32 alphabet (A-Z, 2-7).
Example:
let encoded = "JBSWY3DPEBLW64TMMQ======" if let data = encoded.base32DecodedData { // Use decoded data }Declaration
Swift
public var base32DecodedData: Data? { get } -
Encodes the string to base32 format.
Uses the standard base32 alphabet (A-Z, 2-7).
Example:
let text = "Hello" let encoded = text.base32EncodedStringDeclaration
Swift
public var base32EncodedString: String { get } -
Decodes a base32-encoded string to a string.
Declaration
Swift
public func base32DecodedString(_ encoding: String.Encoding = .utf8) -> String?Parameters
encodingText encoding to use (defaults to UTF-8)
Return Value
Decoded string, or nil if decoding fails
-
Decodes a base32hex-encoded string to data.
Uses the extended hex alphabet (0-9, A-V).
Declaration
Swift
public var base32HexDecodedData: Data? { get } -
Encodes the string to base32hex format.
Uses the extended hex alphabet (0-9, A-V).
Declaration
Swift
public var base32HexEncodedString: String { get } -
Decodes a base32hex-encoded string to a string.
Declaration
Swift
public func base32HexDecodedString(_ encoding: String.Encoding = .utf8) -> String?Parameters
encodingText encoding to use (defaults to UTF-8)
Return Value
Decoded string, or nil if decoding fails
-
Computes the SHA-256 hash of the string.
Declaration
Swift
var sha256Hash: Data { get } -
Encodes the string to base64 format.
Converts the string to UTF-8 data and then encodes it as a base64 string.
Example:
let text = "Hello, Stellar!" let encoded = text.base64Encoded()Declaration
Swift
public func base64Encoded() -> String?Return Value
Base64-encoded string, or nil if encoding fails
-
Decodes a base64-encoded string.
Decodes the base64 string to data and then converts it to a UTF-8 string.
Example:
let encoded = "SGVsbG8sIFN0ZWxsYXIh" let decoded = encoded.base64Decoded() // "Hello, Stellar!"Declaration
Swift
public func base64Decoded() -> String?Return Value
Decoded string, or nil if decoding fails
-
URL-encodes the string for use in query parameters.
Encodes characters that are not allowed in URL query parameters and keys.
Example:
let param = "Hello World & More" let encoded = param.urlEncoded // "Hello%20World%20%26%20More"Declaration
Swift
var urlEncoded: String? { get } -
URL-decodes the string by removing percent encoding.
Example:
let encoded = "Hello%20World" let decoded = encoded.urlDecoded // "Hello World"Declaration
Swift
var urlDecoded: String? { get } -
Validates if the string is a fully qualified domain name (FQDN).
Declaration
Swift
var isFullyQualifiedDomainName: Bool { get }Return Value
True if the string matches FQDN format, false otherwise
-
Extended encoding types beyond standard String.Encoding.
See moreDeclaration
Swift
enum ExtendedEncoding -
Converts the string to data using extended encoding types.
For hexadecimal encoding, converts a hex string (with optional “0x” prefix) to binary data.
Example:
let hex = "0x1234abcd" let data = hex.data(using: .hexadecimal)Declaration
Swift
func data(using encoding: ExtendedEncoding) -> Data?Parameters
encodingExtended encoding type to use
Return Value
Converted data, or nil if conversion fails
-
Converts a hexadecimal string to WrappedData32.
Removes leading zeros and converts the hex string to 32-byte wrapped data. Used for Soroban contract data encoding.
Declaration
Swift
func wrappedData32FromHex() -> WrappedData32Return Value
WrappedData32 representation of the hex string
-
Decodes strkey ed25519 public key (“G…”) to raw data
Declaration
Swift
public func decodeEd25519PublicKey() throws -> Data -
Returns true if the string represents a valid strkey ed25519 public key. Must start with “G”
Declaration
Swift
public func isValidEd25519PublicKey() -> Bool -
Decodes strkey ed25519 seed (“S…”) to raw data.
Declaration
Swift
public func decodeEd25519SecretSeed() throws -> Data -
Returns true if the string represents a valid strkey ed25519 seed. Must start with “S”
Declaration
Swift
public func isValidEd25519SecretSeed() -> Bool -
Decodes strkey med25519 public key (“M…”) to raw data.
Declaration
Swift
public func decodeMed25519PublicKey() throws -> Data -
Returns true if the string represents a valid strkey med25519 public key. Must start with “M”
Declaration
Swift
public func isValidMed25519PublicKey() -> Bool -
Decodes strkey PreAuthTx (“T…”) to raw data.
Declaration
Swift
public func decodePreAuthTx() throws -> Data -
Returns true if the string represents a valid strkey PreAuthTx . Must start with “T”
Declaration
Swift
public func isValidPreAuthTx() -> Bool -
Decodes strkey sha256 hash (“X…”) to raw data.
Declaration
Swift
public func decodeSha256Hash() throws -> Data -
Returns true if the string represents a valid strkey sha256 hash . Must start with “X”
Declaration
Swift
public func isValidSha256Hash() -> Bool -
Decodes strkey signed payload (“P…”) to Ed25519SignedPayload.
Declaration
Swift
public func decodeSignedPayload() throws -> Ed25519SignedPayload -
Returns true if the string represents a valid strkey signed payload . Must start with “P”
Declaration
Swift
public func isValidSignedPayload() -> Bool -
Decodes strkey contract id (“C…”) to raw data.
Declaration
Swift
public func decodeContractId() throws -> Data -
Decodes strkey contract id (“C…”) to raw data and then returns the hex encoded string representation of the raw data.
Declaration
Swift
public func decodeContractIdToHex() throws -> String -
Returns true if the string represents a valid strkey contract id . Must start with “C”
Declaration
Swift
public func isValidContractId() -> Bool -
Decodes strkey claimable balance id (“B…”) to raw data.
Declaration
Swift
public func decodeClaimableBalanceId() throws -> Data -
Decodes strkey claimable balance id (“B…”) to raw data and then returns the hex encoded string representation of the raw data.
Declaration
Swift
public func decodeClaimableBalanceIdToHex() throws -> String -
Returns true if the string represents a valid strkey claimable balance id. Must start with “B”
Declaration
Swift
public func isValidClaimableBalanceId() -> Bool -
Decodes strkey liquidity pool id (“L…”) to raw data.
Declaration
Swift
public func decodeLiquidityPoolId() throws -> Data -
Decodes strkey liquidity pool id (“L…”) to raw data and then returns the hex encoded string representation of the raw data.
Declaration
Swift
public func decodeLiquidityPoolIdToHex() throws -> String -
Returns true if the string represents a valid strkey liquidity pool id. Must start with “L”
Declaration
Swift
public func isValidLiquidityPoolId() -> Bool -
Decodes strkey muxed account id (med25519 public key - “M…”) to MuxedAccountXDR.
Declaration
Swift
public func decodeMuxedAccount() throws -> MuxedAccountXDR -
Encodes a contract id from its hex representation into its strkey representation (“C…”).
Throws
StellarSDKError if the string is not valid hexadecimalDeclaration
Swift
public func encodeContractIdHex() throws -> StringReturn Value
StrKey encoded contract id
-
Encodes a claimable balance id from its hex representation into its strkey representation (“B…”).
Throws
StellarSDKError if the string is not valid hexadecimalDeclaration
Swift
public func encodeClaimableBalanceIdHex() throws -> StringReturn Value
StrKey encoded claimable balance id
-
Encodes a liquidity pool id from its hex representation into its strkey representation (“L…”).
Throws
StellarSDKError if the string is not valid hexadecimalDeclaration
Swift
public func encodeLiquidityPoolIdHex() throws -> StringReturn Value
StrKey encoded liquidity pool id
-
Checks if the string is a valid hexadecimal representation of data.
Declaration
Swift
public func isHexString() -> BoolReturn Value
True if the string is valid hexadecimal, false otherwise
-
Encodes the string to XDR format.
Converts to UTF-8 bytes and encodes as a variable-length array.
Declaration
Swift
public func xdrEncode(to encoder: XDREncoder) throws -
Undocumented
Declaration
Swift
public init(fromBinary decoder: XDRDecoder) throws
View on GitHub
Install in Dash