- 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")
推薦閱讀
- 數(shù)據(jù)浪潮
- Hands-On Machine Learning with Microsoft Excel 2019
- Creating Mobile Apps with Sencha Touch 2
- 虛擬化與云計(jì)算
- 正則表達(dá)式必知必會(huì)
- PySpark大數(shù)據(jù)分析與應(yīng)用
- 商業(yè)分析思維與實(shí)踐:用數(shù)據(jù)分析解決商業(yè)問(wèn)題
- Live Longer with AI
- 數(shù)據(jù)庫(kù)技術(shù)及應(yīng)用教程
- 數(shù)據(jù)庫(kù)設(shè)計(jì)與應(yīng)用(SQL Server 2014)(第二版)
- 企業(yè)級(jí)容器云架構(gòu)開(kāi)發(fā)指南
- 改變未來(lái)的九大算法
- 智能與數(shù)據(jù)重構(gòu)世界
- MySQL數(shù)據(jù)庫(kù)應(yīng)用與管理
- 區(qū)塊鏈應(yīng)用開(kāi)發(fā)指南:業(yè)務(wù)場(chǎng)景剖析與實(shí)戰(zhàn)