Swift 2.0 Learning Note (Day 21)--function return value

Source: Internet
Author: User

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

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.