官术网_书友最值得收藏!

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")
主站蜘蛛池模板: 扬州市| 炉霍县| 班戈县| 乌拉特后旗| 长汀县| 富川| 怀化市| 奉化市| 旬阳县| 凤翔县| 高阳县| 开平市| 聂拉木县| 莆田市| 华池县| 长乐市| 香格里拉县| 德化县| 刚察县| 蛟河市| 南平市| 广水市| 金堂县| 大姚县| 广河县| 大埔区| 易门县| 新野县| 府谷县| 博乐市| 武定县| 五华县| 沾益县| 来凤县| 滕州市| 来安县| 佳木斯市| 海林市| 吉木萨尔县| 遂宁市| 景德镇市|