Open Source projects from That Thing in Swift

PermissionScope

PermissionScope

Intelligent iOS permissions UI and unified API — 2,241⭐️ — GithubDocumentation

PermissionScope

Pantry

The missing light persistence layer for Swift — 433⭐️ — GithubDocumentation

String Format Specifiers

Ease of use first, fancy formatting second

We’ve all grown to love the string format specifiers doc from Apple and because it was baked into NSString, it was super easy to use in Objective-C. Here’s something you might do:

NSLog(@"The current time is %02d:%02d", 10, 4);

While standard string interpolation is useful in Swift, all the power of format specifiers aren’t available using the interpolation syntax. Luckily the format specifiers have been added into the String type during beta. While we can’t do this right from the Swift String type, we can easily use NSString to accomplish our goals.

let timeString = String(format: "The current time is %02d:%02d", 10, 4)

And since NSString and String are interchangeable in Swift, you can easily use the one formatter or another and pass the results right back to Objective-C or Swift.


Questions or comments? Find us on twitter or submit an issue on github

You'll get 1-2 emails per month