Created
April 28, 2019 15:17
-
-
Save pavel-sazonov/7f81e8458a742b2955a43007ac97a735 to your computer and use it in GitHub Desktop.
extension String foк unique string (untited1, untitled2, ...)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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