Swift Examples

SwiftOct 23, 2026

Swift aligned plain-text table renderer

Renders headers and rows as a width-aligned plain-text table with padded columns and a separator rule.

formattingtableterminal
000
SwiftOct 23, 2026

Swift strict Base64 encode and decode

Encodes UTF-8 text to Base64 and decodes it back, rejecting malformed input with a typed error.

decodingencodingbase64
000
SwiftOct 23, 2026

Swift field-level input validation collector

Checks required fields and value ranges, returning a list of per-field errors instead of stopping at the first one.

inputerrorsvalidation
000
SwiftOct 23, 2026

Swift JSON decode with readable error messages

Wraps JSONDecoder to report missing keys, type mismatches, and corrupted payloads as short readable messages.

error-messagesdecodingjson
000
SwiftOct 23, 2026

Swift URL query string builder and parser

Builds URLs from dictionaries and parses query parameters back into a plain Swift dictionary with empty fallbacks.

query-stringurlparsing
000
SwiftOct 23, 2026

Swift bounded worker pool with Result collection

Runs tasks on a fixed number of concurrent workers and returns every result or thrown error in input order.

concurrencyworker-pooldispatch
000
SwiftOct 23, 2026

Swift URLSession GET JSON with timeout

Runs a synchronous JSON GET request with a hard timeout and returns Foundation objects parsed from the response.

urlsessionhttpjsontimeout
000
SwiftOct 23, 2026

Swift environment configuration loader with validation

Reads host, port, and debug settings from environment variables with defaults, bounds checks, and typed errors.

environmentconfigurationvalidation
000
SwiftOct 23, 2026

Swift token bucket rate limiter class

Caps average call rate while permitting bursts up to the bucket size using lazy, time-based token refill.

concurrencytoken-bucketrate-limiting
000
SwiftOct 23, 2026

Swift dictionary-backed LRU cache struct

Implements a small generic LRU cache that evicts the least recently used entry once capacity is exceeded.

data-structureslrucache
000
SwiftOct 23, 2026

Swift stable multi-key sort with nil ordering

Sorts dictionaries by several keys with a stable tie-break, placing records that lack a key after those that have it.

sortingstabilitycomparator
000
SwiftOct 23, 2026

Swift chunked collection batches of fixed size

Splits any Collection into consecutive arrays of at most N elements while preserving the original order.

chunkingcollectionbatch
000
SwiftOct 23, 2026

Swift line-by-line file reader with FileHandle

Streams a text file through FileHandle and calls a closure for each newline-delimited line as it arrives.

streamingfilehandlefile
000
SwiftOct 23, 2026

Swift recursive dictionary deep merge and clone

Clones nested JSON-compatible dictionaries and merges two trees recursively, with right-hand values winning.

mergedictionarydeep-clone
000
SwiftOct 23, 2026

Swift retry helper with capped exponential backoff

Adds a reusable jittered exponential backoff retry helper that caps the wait time between attempts.

error-handlingbackoffretryjitter
000