1. The same way as before
2. Code
1 //2 //Viewcontroller.swift3 //SwiftLesson34 //5 //Created by Sheyulon on 14-10-2.6 //Copyright (c) 2014 Dylan. All rights reserved.7 //8 9 Import UIKitTen One classViewcontroller:uiviewcontroller { A - Overridefunc viewdidload () { - super.viewdidload () the -println (Self.sum (1, num2:2)) - -println (self.sum_6 (number:1, Number1:2)) +println (Self.sum_7 (NUM1:1, num2:3)) - + } A at Overridefunc didreceivememorywarning () { - super.didreceivememorywarning () - } - - //func - inFunc sum (num1:int, Num2:int)Int { - returnNUM1 +num2 to } + - //3 ways to define a function with a return value of void the func sum_1 (num:int) { * $ }Panax Notoginseng -Func sum_2 (Num:int)() { the + } A theFunc Sum_3 (Num:int)Void { + - } $ $ //No parameter note cannot omit parameter brackets -Func Sum_4 ()Int { - return 1; the } - Wuyi //returns a tuple theFunc sum_5 (Num:int)(name:string, age:int) { - return("Alice", -) Wu } - About //External Parameter name $Func sum_6 (number num:int, Number1 num2:int),Int { - returnNum +num2 - } - A //Use # to simplify external parameters +Func sum_7 (#num1: Int, Num2:int)Int { the returnNUM1 +num2 - } $ the //function Default Parameters theFunc sum_8 (#num: Int, name:string ="Alice"),String { the returnName +String (num) the } - in //add an underscore to the parameter name with the default parameter value, and you do not have to write the external parameter name when calling the function theFunc sum_9 (#num: Int, _ name:string ="Alice"),String { the returnName +String (num) About } the the //Append theFunc sum_10 (var name:string ="Alice", Strings:string, Count:int)String { + forIinch 0.... Count { -Name + ="Dylan" the }Bayi returnname the } the - -}
function definition of Swift Foundation