28 lines
1.1 KiB
Markdown
28 lines
1.1 KiB
Markdown
---
|
||
title: Functions
|
||
localeTitle: Функции
|
||
---
|
||
## Функции
|
||
|
||
Функции в Swift состоят из параметров и возвращаемого типа. Функции могут быть созданы с использованием этой базовой структуры:
|
||
```Swift
|
||
func sayHello(nameOfPerson: String) -> String {
|
||
let hello = "Привет, " + nameOfPerson + "."
|
||
print(hello)
|
||
}
|
||
|
||
sayHello (nameOfPerson: "Стив")
|
||
```
|
||
В данном примере, функция `sayHello` принимает строку, содержащюю имя, как параметр и печатает фразу `«Привет, Стив.»`.
|
||
|
||
## Параметры функции
|
||
|
||
Функции не требуют ввода входных параметров или возвращаемых типов. Однако скобки после имен функций являются обязательными.
|
||
```Swift
|
||
func helloSteve () {
|
||
print ("Привет, Стив.")
|
||
}
|
||
|
||
helloSteve () // Это выводит «Привет, Стив.»
|
||
```
|