© 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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.