Posts

Showing posts from September, 2018

iOS Swift String Cheat Sheet

Repost from: https://useyourloaf.com/blog/swift-string-cheat-sheet/ The Swift String API is  hard  to get used to. It has also changed over time as the Swift language and the standard library have developed. I first wrote this guide for Swift 2 and have since needed to update it for Swift 3, Swift 4 and Swift 4.2. So for my future reference and yours if you are struggling to make sense of it all here is my Swift String Cheat Sheet: Xcode Playground You can get the latest version of the Xcode playground from my GitHub repository: Xcode Strings Playground Version History See the following posts for the main changes since I first wrote this guide for Swift 2: Updating Strings for Swift 4.2 Updating Strings For Swift 4 Updating Strings For Swift 3 Initializing A String There are an almost endless number of ways to create a String, using literals, conversions from other Swift types, Unicode, etc. var emptyString = "" // Empty (Mutable) Stri...