Swift 2.0 Learning Notes (Day 20)--passing references to parameters in functions

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 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

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.