Skip to content

Instantly share code, notes, and snippets.

@atierian
Created August 28, 2020 01:19
Show Gist options
  • Save atierian/4d58926e196cf36a09ebded9ee0f89b3 to your computer and use it in GitHub Desktop.
Save atierian/4d58926e196cf36a09ebded9ee0f89b3 to your computer and use it in GitHub Desktop.
Add prefix to String if not already present (taken from hackingwithswift.com)
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