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