© Wallace Wang 2017

Wallace Wang, macOS Programming for Absolute Beginners, 10.1007/978-1-4842-2662-9_11

11. Storing Code in Functions

Wallace Wang

(1)San Diego, California, USA

Every program stores data (in variables or in data structures such as arrays, sets, or dictionaries) and then manipulates that data somehow. Code that manipulates data is called an algorithm .

If you want to use an algorithm in more than one place in your program, you can copy that code and paste it in a separate location. However, this can cause problems if you later want to modify the code. If you made 20 copies of the same algorithm, you’d now have to modify all 20 copies throughout your program. Not only would this be time-consuming, but it would be error-prone as well. ...

Get macOS Programming for Absolute Beginners: Developing Apps Using Swift and Xcode now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.