/** * Definition and invocation of functions*/func Showintegerarray (Array:[int]) { forAinchArray {println ("\ (a)")}}showintegerarray ([1,2,3]) func maxofvalue (a:int,b:int)-int{returna > B?a:b}println (Maxofvalue (3,5) ) func Showhelloword () {println ("Hello World")}showhelloword () Let P0: (x:double,y:double)= (0,0) let P1: (x:double,y:double)= (6,6) func getlengthandwidth (p0: (x:double,y:double), p1: (x:double,y:double))-(length:double,width:double) {return(ABS (P0).1-p1.1), ABS (P0.0-p1.0)) }let W=getlengthandwidth (P0, p1). Widthlet Len=getlengthandwidth (P0, p1). Lengthprintln ("\ (len): \ (w)")/** * internal and external parameters of the function*///func divisionopertation (Dividend a:double,divsior b:double) (Double)//{//return A/b//}//Add # represents internal and external parametersFunc divisionopertation (#dividend:D ouble, #divsior:D ouble)(Double) {returnDividend/Divsior}let Res= Divisionopertation (Dividend:3.5, Divsior:1.2) println (res)/** * Default parameters for functions*///func joinstring (s1:string,tostring s2:string, joiner s3:string = "#") (String)//{//return S1+S3+S2// // // //}//The default parameters can be placed in any locationFunc joinstring (s1:string,tostring s2:string, joiner:string ="?"),(String) {returns1+joiner+S2}let Str= Joinstring ("Hello"Tostring:" World", Joiner:"#") println (str)/** * Constant parameters and variable parameters*///default constants cannot be modified to protect//func swap (var a:int,var b:int)//{//Let t = a//A = b//B = t//}func swap (inout a:int,inout b:int) {Let T=a A=b b=T}/** * Input/output function (inout)*/var x=Tenvar y= +Swap (&x, &y) println ("\ (x), \ (y)")/** * variable parameter function*/
Swift (v) functions of Swift