Skip to content

Instantly share code, notes, and snippets.

View jesskturner's full-sized avatar

Jessica Turner jesskturner

View GitHub Profile
@jesskturner
jesskturner / string-truncate.swift
Last active March 18, 2018 17:37 — forked from aorcsik/string-truncate.swift
A little truncate function extension for the default String type
extension String {
/// Truncates the string to length number of characters and
/// appends optional trailing string if longer
func truncate(length: Int, trailing: String? = nil) -> String {
if self.characters.count > length {
return self.substringToIndex(self.startIndex.advancedBy(length)) + (trailing ?? "")
} else {
return self
}
}