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

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")
主站蜘蛛池模板: 鄂伦春自治旗| 衡阳市| 新闻| 靖江市| 深圳市| 余姚市| 乌鲁木齐市| 剑河县| 本溪| 吴桥县| 如皋市| 枣阳市| 买车| 潼关县| 同江市| 大宁县| 平乐县| 九江市| 安义县| 黎川县| 呈贡县| 万州区| 迭部县| 丰顺县| 铁岭县| 东海县| 钦州市| 项城市| 大方县| 徐闻县| 中牟县| 和平县| 河北区| 莱阳市| 万荣县| 锡林浩特市| 南阳市| 鱼台县| 胶州市| 乌鲁木齐市| 交口县|