2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Functions
|
|
|
|
localeTitle: Funciones
|
|
|
|
---
|
|
|
|
## Funciones
|
|
|
|
|
2019-07-03 02:45:30 +02:00
|
|
|
Las funciones en Swift consisten en un parámetro y un tipo de retorno. Las funciones se pueden crear utilizando esta estructura básica:
|
|
|
|
```Swift
|
|
|
|
func sayHello(nameOfPerson: String) -> String {
|
|
|
|
let hello = "Hola," + nameOfPerson + "."
|
|
|
|
print(hello)
|
|
|
|
}
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-03 02:45:30 +02:00
|
|
|
sayHello(nameOfPerson: "Steve")
|
|
|
|
```
|
|
|
|
En este ejemplo, la función sayHello coge una cadena de palabras e imprime la frase `"Hola, Steve."`.
|
2018-10-12 15:37:13 -04:00
|
|
|
|
|
|
|
## Parámetros de función
|
|
|
|
|
2019-07-03 02:45:30 +02:00
|
|
|
Las funciones no requieren ningún parámetro de entrada o tipo de retorno. Sin embargo, esto requiere los paréntesis después de nombrar las funciones.
|
|
|
|
```Swift
|
|
|
|
func helloSteve() {
|
|
|
|
print("Hola, Steve.")
|
|
|
|
}
|
|
|
|
|
|
|
|
helloSteve() // Esto imprime "Hola, Steve."
|
|
|
|
```
|