[Swift Learning seven] several operator exercises

Source: Internet
Author: User

/* Empty-fit operator 1: empty-fit operator??    Must be an optional type 2: binocular operator, meaning that the front if not empty, then return to the front (arbitrarily unpacked), or return to the back. The following must not be empty. */var Emptyarra:[int]?var emptyarrb:[int]=[4,5]/* Two return meaning, executed is above the */func getnotnoneempty (), [Int] {if Emptya RrA?. Count?? 1 > 0{return Emptyarra?? EMPTYARRB} return (Emptyarra! = nil)? emptyarra! : Emptyarrb}print (Getnotnoneempty ())/*=== operator, determines whether two instances are the same instance, can only be used for reference types ~*/class Testoperator {var p:int = 0}let T1 = TestO Perator () Let t2 = T1t2.p=9print ("issame:\ (T1===T2) t1.p=\ (T1.P)")/*$ operator, if not, you have to have a formal parameter, such as emptyarrc~ need to note that if you use the $ access,    To give a type, unexplained ~*/let EMPTYARRC = emptyarrb.map {(avalue:int), Int in if Avalue > 3 {return avalue + 4 } return Avalue}print (EMPTYARRC) let emptyarrd:[int] = Emptyarrb.map ({if $ > 3 {return $4} r Eturn $}) print (EMPTYARRD) func emptymap (avalue:int), Int {if avalue > 3 {return avalue + 4} RE Turn Avalue}let Emptyarre = Emptyarrb.map (emptymap) print (Emptyarre)

[Swift Learning seven] several operator exercises

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.