Skip to content

Instantly share code, notes, and snippets.

@RustyKnight
Created August 30, 2018 22:17
Show Gist options
  • Save RustyKnight/5464ccf436159e4984a244b6c353e73c to your computer and use it in GitHub Desktop.
Save RustyKnight/5464ccf436159e4984a244b6c353e73c to your computer and use it in GitHub Desktop.
A simple reminder to myself about how to encode a string from encoding to another
extension String {
func encode(from: String.Encoding, to: String.Encoding) -> String? {
guard let originalData = data(using: from) else {
return nil
}
return String(data: originalData, encoding: to)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment