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