freeCodeCamp/guide/russian/swift/functions/index.md

28 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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