??
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 parameter as a reference, which is also achievable, andSwift provides ainoutkeyword can be implemented. Look at one of the following examples:
Func Increment (inout value:double, amount:double = 1.0) { value + = amount} var value:double = 10.0 Increment (&v alue) print (value) increment (&value, amount:100.0) print (value)
CodeIncrement (&value)is the calling functionIncrement, the increment is the default value, where&value(in front of the variable, add&symbols, removingvalueaddress) is a method of passing a reference, which, when defining a function, identifies the parameter with theinoutcorrespond to one another.
CodeIncrement (&value,amount:100.0)also called functionsIncrement, the amount of growth is100.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
?
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
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Swift 2.0 Learning Notes (Day 20)--passing references to parameters in functions