A Swift library for type-safe, printf-compatible string formatting on iOS and macOS with validation and localization support.
Sprinter is a Swift library for formatting strings on iOS and macOS using printf/NSLog conventions. It solves Swift's limitations in string formatting by providing full printf spec compliance, type safety, and runtime validation to prevent errors and crashes. It also supports localization and reusable format strings for better performance.
iOS and macOS developers who need robust, cross-platform string formatting with printf compatibility, especially those working with localized strings, Objective-C interop, or requiring runtime validation.
Developers choose Sprinter over Swift's native formatter for its full printf spec support, type safety that catches errors early, and ability to inspect argument types for testing. It bridges gaps in Swift's handling of C strings and Objective-C types while offering thread-safe, reusable formatting objects.
A library for formatting strings on iOS and macOS
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Validates format strings and argument types at runtime, throwing descriptive FormatString.Error for mismatches, which prevents crashes and memory corruption common with Swift's native formatter.
Supports standard IEEE printf tokens like %s for C strings and Apple's Objective-C extensions, enabling cross-platform string code that Swift's String(format:) cannot handle, as highlighted in the README's examples.
Includes an optional locale parameter for formatting numbers and punctuation according to different regions, demonstrated with examples for en-US, fr-FR, and de-DE locales in the README.
FormatString instances are stateless and can be cached and reused across threads safely, improving performance by avoiding repeated parsing and formatter initialization, as noted in the thread safety and advanced usage sections.
Exposes the types property to inspect required argument types, useful for building validation tools or automated tests for localized strings, as mentioned in the integration and why sections.
Requires creating FormatString objects and handling errors explicitly with try-catch, adding complexity compared to Swift's simpler String(format:) method, as shown in the integration examples where both initialization and printing can throw.
Primarily targets iOS and macOS; the README specifies support for iOS 9 or macOS 10.0 and above but lacks mention of watchOS, tvOS, or Linux, making it less suitable for broader Swift projects.
The need to parse and cache FormatString objects introduces overhead that might be unnecessary for straightforward, non-reused formatting tasks, as acknowledged in the advanced usage section recommending caching for efficiency.