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

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")
主站蜘蛛池模板: 博白县| 平谷区| 田东县| 余姚市| 山西省| 龙里县| 长沙县| 嵩明县| 济阳县| 禄劝| 西吉县| 宣汉县| 嘉荫县| 汉寿县| 长顺县| 商都县| 竹山县| 博乐市| 闻喜县| 诸暨市| 临湘市| 正安县| 封开县| 玉树县| 英超| 灯塔市| 潍坊市| 怀化市| 宁远县| 湖南省| 衡山县| 海南省| 深圳市| 沈阳市| 盘山县| 渭源县| 华坪县| 邳州市| 石城县| 大港区| 贡觉县|