Created
August 30, 2018 22:17
-
-
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
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 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