Swift Examples
Swift aligned plain-text table renderer
Renders headers and rows as a width-aligned plain-text table with padded columns and a separator rule.
Swift strict Base64 encode and decode
Encodes UTF-8 text to Base64 and decodes it back, rejecting malformed input with a typed error.
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.
Swift JSON decode with readable error messages
Wraps JSONDecoder to report missing keys, type mismatches, and corrupted payloads as short readable messages.
Swift URL query string builder and parser
Builds URLs from dictionaries and parses query parameters back into a plain Swift dictionary with empty fallbacks.
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.
Swift URLSession GET JSON with timeout
Runs a synchronous JSON GET request with a hard timeout and returns Foundation objects parsed from the response.
Swift environment configuration loader with validation
Reads host, port, and debug settings from environment variables with defaults, bounds checks, and typed errors.
Swift token bucket rate limiter class
Caps average call rate while permitting bursts up to the bucket size using lazy, time-based token refill.
Swift dictionary-backed LRU cache struct
Implements a small generic LRU cache that evicts the least recently used entry once capacity is exceeded.
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.
Swift chunked collection batches of fixed size
Splits any Collection into consecutive arrays of at most N elements while preserving the original order.
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.
Swift recursive dictionary deep merge and clone
Clones nested JSON-compatible dictionaries and merges two trees recursively, with right-hand values winning.
Swift retry helper with capped exponential backoff
Adds a reusable jittered exponential backoff retry helper that caps the wait time between attempts.