There are two functions defined here, the second has a parameter, and there is a return value, the return value is separated by a, the first one is a normal function, no parameter return value.
5 ; func test () { print ("asdfa");}
Call
,Int { return1}
Call
Test1 (5)
There are constants, functions with no fixed parameters, variable parameters ... Give default value directly = a value
// 1. With default values, the parameters are all in the back (parameters are not variable) // 2. Call the parameter order as much as possible in the order in which the function is declared func Add (initnum:int = 0,numbers:int ...) -Int { var totals = initnum for in Numbers { + = num }return totals}
parameter is a variable, parameter is a fairly pointer, reference parameter
// by default, its arguments are constants var a:int)-int{ //return (+ +a)}var6 = inout-int{ //a++ return a}vtest2 (&m) m
A function is a first-class citizen, which means that it can be returned as another value. This returns the return value of the function in the function.
Func makeincrementer (),return1 +return var increment = makeincrementer () increment (7)
Functions can also be passed as arguments to another function.
Here we will lessthantenchua this function into the function hasanymatches find the number less than 10
Func hasanymatches (list:int[], Condition:int-Bool)Bool { forIteminchList {ifcondition (item) {return true } } return false} func Lessthanten (number:int)-Bool {returnNumber <Ten } varnumbers = [ -, +,7, A] Hasanymatches (Numbers, Lessthanten)
Swift's functions