2018-10-12 20:35:31 +00:00
---
title: Functions
localeTitle: 功能
---
## 功能
2018-10-29 21:59:52 +00:00
Swift中的函数由参数和返回类型组成。可以使用以下基本结构创建函数: \`\`\`斯威夫特 func sayHello( nameOfPerson: String) - > String { let hello =“Hello, ”+ nameOfPerson +“。” return hello }
2018-10-12 20:35:31 +00:00
2018-10-29 21:59:52 +00:00
运行函数: print(sayHello (nameOfPerson: “史蒂夫”)) ` `` In this example, the function sayHello takes in a string name and prints out the phrase` 输出结果是: “Hello, 史蒂夫。”。
2018-10-12 20:35:31 +00:00
## 功能参数
函数不需要任何输入参数或返回类型。但是,在命名函数后,这需要括号。 \`\`\`斯威夫特 func helloSteve( ) { 打印(“你好,史蒂夫。”) }
2018-10-29 21:59:52 +00:00
helloSteve( ) //打印出“Hello, Steve”。 \`\`\`