Press "Enter" to skip to content

Truncate String in Swift

I was doing some fancy debug printing for a class and wanted to display truncated text. Since the days when I was using PHP and Smarty I grew fond of the truncate modifier, which lets you specify the length of the truncated text and some trailing character sequence which is appended if the string is indeed truncated. So after figuring how this is done in Swift, I created a little extension for the String type.

PS.: extending types in Swift is awesome, imho 🙂

Be First to Comment

Leave a Reply

%d bloggers like this: