Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDaniel Kokin
1,496 PointsConfused 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;
break;
1 Answer
Matt Casanova
15,864 PointsTake 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.