O'Reilly logo

Objective-C Quick Syntax Reference by Matthew Campbell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 15

image

Switch Statements

Switch Statements Defined

Switch statements are used to execute code based on the value of an integer. To make a switch statement work, you need to define a level variable and then you need to write a code block for each possible value of the level variable that you expect.

For this chapter, let’s assume you are writing code to help you do some geometry work. You have different shapes that you need to work with and you want to calculate the area of each shape. You can keep track of what type of shape you are working with by using an NSInteger variablelike shape.

NSInteger shape = 0;

Each value of the NSInteger shape ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required