The Swift Foundation method in combat

Source: Internet
Author: User

1. The same as before

2. Code

1 //2 //Viewcontroller.swift3 //Switflesson_exam4 //5 //Created by Sheyulon on 14-10-7.6 //Copyright (c) 2014 Dylan. All rights reserved.7 //8 9 Import UIKitTen  One classViewcontroller:uiviewcontroller { A  -     Overridefunc viewdidload () { - super.viewdidload () the          -         //1. -         //Change Temper -         //initialization of 2 types of tuples +var a ="Alice" -var B ="Dylan" +var myType =(A, b) A          at var name:string - var family:string -(name, family) = ("Alice","Dylan") -          -         //test func Change -Swap (&a, with: &b) in println (a) - println (b) to          +         //2. -         //Print String the         //test func flexstring *println (Flexstrings (S1:"Alice", S2:"Dylan")) $         Panax Notoginseng         //3. -         //Sumany the         //test func Sumany +println (Sumany (1,2,3)) A          the         //4. +         //Countfrom -         //test func Countfrom $Countfrom (from:1, to:5) $     } -      -     /** the 1. Fun Change - Exchange values for 2 arbitrary objectsWuyi     */ theFunc swap<t>(InOut a:t, inout with b:t) { -(A, b) =(b, a) Wu     } -      About     /** $ 2. Func flexstrings - Output String -     */ -Func flexstrings (s1:string ="", s2:string =""),String { A         returnS1 + s2 = =""?"None": s1+S2 +     } the      -     /** $ 3. Func Sumany the     */ theFunc Sumany (Anys:any ...)String { the         returnString ( the(Anys.map ({iteminch -                 SwitchItem { in                  Case ""  asString,0  asInt: the                     return-Ten the                  CaseLet S asStringwhereS.toint () >0: About                     returnS.toint ()! the                  Case  isInt: the                     returnItem asInt the                 default: +                     return 0 -                 } the}) as[Int]). Reduce0, combine: {Bayi$0+ $1 the             }) the         ) -     } -      the     /** the 4. Func Countfrom the     */ the func countfrom (#from: Int, to:int) { - println (from) the         ifFrom <To { theCountfrom (From:from +1, to:to) the         }94     } the  the     Overridefunc didreceivememorywarning () { the super.didreceivememorywarning ()98         //Dispose of any resources the can be recreated. About     } - 101 102}

The Swift Foundation method in combat

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.