Introduction to swift1.2 language functions and closure functions

Source: Internet
Author: User

Introduction to swift1.2 language functions and closure functions

In programming, as the processing problem becomes more and more complex, the amount of code increases rapidly. Where a large number of code tends to repeat or approximate each other. The code will be difficult to maintain if it is not addressed in an effective manner.

Introduction to swift1.2 language functions and closure functions in order to solve this problem, the concept of function has been put forward. Functions can be used to encapsulate the code of a particular function and then be used in many places. This chapter will explain the function and closure of the relevant content of this article selected from the Swift1.2 Language QuickStart University bully .

7.1Function Introduction

A function is a block of code that performs a specific task. The use of functions can bring a lot of benefits to development. Two points are summarized below.

1. The structure is clear and easy to understand

if the code in a program is very long and the functionality of the implementation is not the same, you can extract the code snippet for each function to use as a function. This makes the program structure clear and easy to understand. The following figure 7.1 is the best implementation.


Figure 7.1 function using 1

2. Reduce the amount of code written and time

in a program, a code snippet that has the same functionality can be presented as a function. In this way, you can reduce the amount of code written, which shortens development time. The following figure 7.2 is the best embodiment.


Figure 7.2 using Functions 2

3. form of function

A complete function consists of a func keywords, function names, parameter tables, and return value type combinations of functions, in the form 7.3 is shown.


Figure 7.3 form of the function

according to the parameter table, the function can be divided into the parameterless function and the parametric function. The following is an introduction to the non-parametric function and the argument function selected from the Swift1.2 Language QuickStart University bully .

?

Introduction to swift1.2 language functions and closure 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.