- Swift Functional Programming(Second Edition)
- Dr. Fatih Nayebi
- 156字
- 2021-07-02 23:54:31
Calling functions
We have covered a general syntax to define a function and method if it resides in an object. Now it is time to talk about how we call our defined functions and methods. That should not be difficult, right? There were complexities with parameters in previous versions of Swift but v3.0 solves the issues and streamlines it.
To call a function, we will use its name and provide its required parameters. For now, we are going to cover the most basic type of parameter, as follows:
funcName(firstParam: firstParamName, secondParam: secondParamName)
To call a method, we need to use the dot notation provided by Swift. The following examples are for instance and class methods:
class AClass {
func instanceMethod(param1: String, param2: String) {
// function body
}
class func classMethod(param1: String, param2: String) {
// function body
}
}
let aClassInstance = AClass()
aClassInstance.instanceMethod(param1: "first string", param2: "second string")
AClass.classMethod(param1: "first string", param2: "second string")
推薦閱讀
- 同步:秩序如何從混沌中涌現
- 達夢數據庫編程指南
- 復雜性思考:復雜性科學和計算模型(原書第2版)
- 輕松學大數據挖掘:算法、場景與數據產品
- MongoDB管理與開發精要
- 業務數據分析:五招破解業務難題
- 揭秘云計算與大數據
- Python醫學數據分析入門
- 數字媒體交互設計(初級):Web產品交互設計方法與案例
- 白話大數據與機器學習
- 大數據技術入門
- SQL Server 2012數據庫管理教程
- IPython Interactive Computing and Visualization Cookbook(Second Edition)
- 淘寶、天貓電商數據分析與挖掘實戰(第2版)
- Google Cloud Platform for Developers