Learning Swift from scratch (day 20)--passing references to parameters in a function

Source: Internet
Author: User

Original articles, welcome reprint. Reprint Please specify: Dongsheng's Blog

Passing references to parameters

A class is a reference type, and other data types such as Integer, float, Boolean, character, string, tuple, collection, enumeration, and struct are all value types.

Sometimes it is possible to pass a value type argument as a reference, which is also achievable, Swift provided by inout keyword can be implemented. Look at one of the following examples:

Func increment (inoutvalue:double, amount:double = 1.0) {Value + = amount} var value:double = 10.0 Increment (&valu e) Print (value) increment (&value,amount:100.0) print (value)


code is the calling function & Value & value address "is a way of passing references, which when defining a function , the parameters are identified with the inout is corresponding to each other.

Code Increment (&value,amount:100.0) also called functions Increment , the amount of growth is 100.0 .

The above code output results are as follows:

11.0

111.0

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
650) this.width=650; "title=" 00.png "src=" http://s3.51cto.com/wyfs02/M00/7C/A6/ Wkiol1bvejvwesazaaas2mbeznc077.png "alt=" Wkiol1bvejvwesazaaas2mbeznc077.png "/>More ProductsIOS,Cocos, mobile Design course please pay attention to the official website of Chi Jie Classroom:http://www.zhijieketang.com
Smart-Jie Classroom Forum Website:http://51work6.com/forum.php


This article is from the "Dongsheng-ios Technical Consultant" blog, make sure to keep this source http://tonyguan.blog.51cto.com/701759/1746249

Learning Swift from scratch (day 20)--passing references to parameters in a function

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.