Last active
July 30, 2020 19:10
-
-
Save lucianoschillagi/df95afadf8ae84d790c853adfb40c1c3 to your computer and use it in GitHub Desktop.
Interpolación de strings
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
| /* Interpolación de strings en Swift */ | |
| // Interpolando una constante | |
| let miNombre = "Luciano" | |
| let stringInterpolado = "Mi nombre es \(miNombre)" | |
| print(stringInterpolado) | |
| // Imprime: "Mi nombre es Luciano" | |
| // Interpolando una expresión | |
| let suma = 2 + 2 | |
| let stringInterpoladoPorUnaExpresion = "El resultado de esta suma es \(suma)" | |
| print(stringInterpoladoPorUnaExpresion) | |
| // Imprime: "El resultado de esta suma es 4" | |
| // Interpolando una variable dentro de un string literal multilínea | |
| var diaActual = "Jueves" | |
| let stringInterpoladoPorUnaVariable = | |
| """ | |
| Hoy, \(diaActual) | |
| tengo turno al dentista | |
| """ | |
| print(stringInterpoladoPorUnaVariable) | |
| // Imprime "Hoy, Jueves, | |
| // tengo turno al dentista" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment