4. Creating Functions

This chapter is all about functions, which are chunks of code you can call to make them run—and they won’t run unless you call them.

So far, the code in the programs we’ve discussed has executed automatically when the programs start. But functions are different; you have to explicitly call a function by name in your code before its code will run. That means that using functions, you can divide your code into smaller parts: the divide and conquer technique.

In Objective-C, functions are a crucial stop on the way to building your own objects. Objects let you package both data and functions—called methods when they’re built into objects—together, as you’ll soon see.

Here is an example of how you might create a function named ...

Get Objective-C: Visual QuickStart Guide 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.