Skip to content

Instantly share code, notes, and snippets.

@pavel-sazonov
Created April 28, 2019 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavel-sazonov/7f81e8458a742b2955a43007ac97a735 to your computer and use it in GitHub Desktop.
Save pavel-sazonov/7f81e8458a742b2955a43007ac97a735 to your computer and use it in GitHub Desktop.
extension String foк unique string (untited1, untitled2, ...)
extension String {
func madeUnique(withRespectTo otherStrings: [String]) -> String {
var possiblyUnique = self
var uniqueNumber = 1
while otherStrings.contains(possiblyUnique) {
possiblyUnique = self + " \(uniqueNumber)"
uniqueNumber += 1
}
return possiblyUnique
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment