Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Object-Oriented Objective-C Memory, Arrays and Loops, Oh My! Immersive Example - Gabe's KFC

Daniel Kokin
Daniel Kokin
1,496 Points

Confused about why I use integerValue

I don't fully understand why it's necessary to add integerValue after 'orderItem' in the switch statement. If the elements in the 'orderArray' are strings why am I converting the element and then comparing it to another string in each case?

    for (NSNumber *orderItem in orderArray) {

        switch ([orderItem integerValue]) {
            case Bucket:
                revenue = revenue + bucket;
                cost = cost + bucketCost;

1 Answer

Take a look at my answer to your last questions because it is related. Since an enum is just a name for a constant integer value and those values are stored in the array as NSNumber objects you need to covert to from NSObject* to the actual integer inside to use the switch statement. Use the the integerValue method on an NSNumber object to convert to an int.