Original articles, welcome reprint. Reprint Please specify: Dongsheng's Blog
Returns a value of 3 forms: no return value, single return value, and multiple return value.
No return value function
The so-called no return result is, in fact, a void type, which represents a type with no data.
There are 3 types of syntax formats for no return-valued functions:
Func function name (argument list) {
Statement Group
}
Func function name (parameter list), () {
Statement Group
}
Func function name (argument list)->void {
Statement Group
}
A return return value statement is not required for a function that has no returned value.
Multiple return value functions
Two ways to achieve it.
One is to declare multiple arguments of a function as reference types at the time the function is defined, so that when the function call ends, the values of these parameters change.
The other is to define the return as a tuple type.
Describes the implementation of a tuple type return multi-value. Look at an example:
Func position (dt:double, Speed: (X:int, Y:int)), (X:int, Y:int) {
Let Posx:int = speed.x * INT (DT)
Let Posy:int = Speed.y * INT (DT)
Return (POSX, posy)
}
Let move = position (60.0, Speed: (10,-5))
Print ("Object displacement: \ (move.x), \ (MOVE.Y)")
Parameter speed: (X:int, Y:int) is a tuple type.
The return value of the position function is the tuple type (X:int, Y:int).
The code calls the function, passing the period is 60 seconds, the speed is (10,? 5).
The output results are as follows:
Object Displacement: 600,-300
Welcome to follow Dongsheng Sina Weibo @tony_ Dongsheng.
Learn about the latest technical articles, books, tutorials and information on the public platform of the smart Jie classroom
?
More Products iOS, Cocos, mobile design courses please pay attention to the official website of Chi Jie Classroom: http://www.zhijieketang.com
Luxgen Classroom Forum Website: http://51work6.com/forum.php
Swift 2.0 Learning Note (Day 21)--function return value