Created
August 28, 2020 01:19
-
-
Save atierian/4d58926e196cf36a09ebded9ee0f89b3 to your computer and use it in GitHub Desktop.
Add prefix to String if not already present (taken from hackingwithswift.com)
This file contains hidden or 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 withPrefix(_ prefix: String) -> String { | |
if self.hasPrefix(prefix) { return self } | |
return "\(prefix)\(self)" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment