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

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")
主站蜘蛛池模板: 济宁市| 全州县| 容城县| 定南县| 日喀则市| 饶平县| 汉沽区| 韶山市| 白水县| 交口县| 十堰市| 革吉县| 霍城县| 霍林郭勒市| 镇宁| 新昌县| 长汀县| 大埔县| 三台县| 永善县| 修文县| 治县。| 河南省| 海安县| 墨江| 巴青县| 合川市| 新和县| 绥德县| 中方县| 灵璧县| 抚宁县| 曲靖市| 鹰潭市| 泽普县| 永新县| 萨迦县| 文登市| 台南县| 永顺县| 石家庄市|