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 Objective-C Basics (Retired) Introduction to Objective-C Inheritance

XCode Output

While following along with the instructor and executing the first build I discovered that my output is different than that shown in the video. The video shows "shape area -1.000000" but for my result I received an output on two parts of the bottom portion of my XCode display - on the left there is "L shape - (Shape *) 0x6080000004210" and on the right "(lldb) is displayed.

I double checked that I entered the same code as the video and suspect that perhaps my XCode settings may need to be adjusted. Any suggestions?

2 Answers

Stone Preston
Stone Preston
42,016 Points

youve got an uncaught exception that is being thrown. so something is wrong with your code. post the code you are using please

I meant to post the code as a comment to your response, but it looks like I posted it as a top level comment. The code is now here if you wouldn't mind giving it a quick look. Much appreciated!

Thanks Stone. Here is the main.m file:

#import <Cocoa/Cocoa.h>
#import "Shape.h"

int main()
{
    Shape *shape = [[Shape alloc] init];
    NSLog(@"Shape area %f", [shape area]);

    return 0;
}

Shape.h file:

#import <Foundation/Foundation.h>

@interface Shape : NSObject
-(float)area;
@end

Shape.m file:

#import "Shape.h"

@implementation Shape

-(float)area {

    return -1;
}

@end

Circle.h file:

#import "Shape.h"

@interface Circle : Shape

@property(nonatomic) float radius;

@end

Circle.m file:

#import "Circle.h"

@implementation Circle
-(float)area {
    return M_PI * self.radius * self.radius;
}

@end