Swift-functions, function pointers

Source: Internet
Author: User

  main.swift//  functiontest-04//import foundationprintln ("function test!") TestFunction ()
The functiontest.swift//functiontest-04//import foundation//function begins with a Func representation of a function//parameter and parameter, and//V1 represents the parameter: String representing the type of the parameter//-& Gt Represents the return value Stringfunc testconcat (v1:string, v2:string)->string{return "\ (v1) and \ (v2)";} The parameter is 0, the return value is three func getInfo (), (string,string,string) {return ("Welcome", "Come", "Baidu");//is a meta-ancestor}// The label is the advantage of OC Swift has brought the label inside OC to the Func testConcat2 (v1:string, Andvalue v2:string,andnumber v3:int)->string{return "\ (v1) A nd \ (v2) and \ (v3);}    Func testfunctioninfunction ()->int{var y = 10;    Add is a function of the LUA scripting language func Add () {//var y = 1; The following y will choose Zui y + = 5;    } add (); return y;} This is a function return value is (Int->int) func getfuncpointer (), (int->int) {func addone (num:int)->int {return nu    m+1; }//Returns the address of a function return addone;}        Func testfunction () {println ("Start test function");    Let V = testconcat ("Hello", "World");        println ("V is \ (v)");    Andvalue: called a label Let V2 = TestConcat2 ("Baidu", Andvalue: "Baidu recruitment", andnumber:100); println ("V2 is\ (v2) ");    Let (v3,v4,v5) = GetInfo ();            println ("v3\ (v3) v4\ (v4) v5\ (V5)");        Let V6 = Testfunctioninfunction ();        println ("V6 Is\ (V6)");    function pointer var funcpointer = Getfuncpointer ();    var V7 = funcpointer (199);        println ("V7 is \ (V7)");    Take the function address/pointer as the parameter var arr = [20,10,333,4,43,33]; var V8 = Hasanymatch (Arr,lessthanten);}        Func Hasanymatch (list: [Int],condition:int, Bool), bool{for item in list{if (condition (item))        {return true;    }} return false; }func Lessthanten (number:int)->bool{return number <= 10;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Swift-functions, function pointers

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.