Swift (v) functions of Swift

Source: Internet
Author: User

/** * 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.