-
-
Save fitomad/8c9e28fbbb0267fa960feac4cbee1788 to your computer and use it in GitHub Desktop.
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
import Foundation | |
let texto: String = "Esto es una cadena de texto que va a pasar a Data y luego a String de nuevo" | |
print("1. \(texto)") | |
// Lo convertimos en `Data` | |
if let data = texto.data(using: .utf8) | |
{ | |
print("2. Tamaño en bytes: \(data)") | |
// Y ahora creamos un `String` a partir de un `Data` | |
if let textoOtraVez = String(data: data, encoding: .utf8) | |
{ | |
print("3. \(textoOtraVez)") | |
} | |
} | |
/* | |
1. Esto es una cadena de texto que va a pasar a Data y luego a String de nuevo | |
2. Tamaño en bytes: 75 bytes | |
3. Esto es una cadena de texto que va a pasar a Data y luego a String de nuevo | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment