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 trial

iOS Objective-C Basics (Retired) Introduction to Objective-C From Structs to Objects

Missing line of code

In the project file of the video there is a extra line of code -(void)setCenter:(NSArray *)center radius:(float)radius; which makes the whole thing work like the video says it should, but the instructor does NOT say or show this in the video at all, without this line of code you get a thread issue.

I was racking my brain why it worked in the video and not on my side, so I finally gave up and downloaded the sample code and found the extra unspoken of line of code in the Sphere.h file.

6 Answers

Stone Preston
Stone Preston
42,016 Points

I went through the video, and following his instruction did not have any trouble. The line you mentioned is not what is causing your errors. are you sure you didnt have a mistake in your code? or maybe set a breakpoint by accident?

below is the code for my main.m

//
//  main.m
//  MyFirstObjectiveCProgram
//
//  Created by turner on 9/26/13.
//  Copyright (c) 2013 treehouse. All rights reserved.
//

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

int main()
{
    Sphere *ball = [[Sphere alloc] init];
    [ball setRadius:25];
    NSLog(@"ball radius %f", [ball radius]);

    return 0;
}

and here is Sphere.h

//
//  Sphere.h
//  MyFirstObjectiveCProgram
//
//  Created by Stone  Preston on 4/28/14.
//  Copyright (c) 2014 treehouse. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Sphere : NSObject

{

    NSArray *_center;
    float _radius;
}

- (void)setRadius:(float)radius;
- (float)radius;

- (void)setCenter:(NSArray *)center;
- (NSArray *)center;



@end

and sphere.m

//
//  Sphere.m
//  MyFirstObjectiveCProgram
//
//  Created by Stone  Preston on 4/28/14.
//  Copyright (c) 2014 treehouse. All rights reserved.
//

#import "Sphere.h"

@implementation Sphere 

- (void)setRadius:(float)radius {

    _radius = radius;

}
- (float)radius {

    return _radius;

}

- (void)setCenter:(NSArray *)center {

    _center = center;
}

- (NSArray *)center {

    return _center;

}


@end

I have not added that line you mentioned and it works fine, so its definitely not that line thats causing your problem. I think you may have set a breakpoint in your project. In your project, press command + y to deactivate all breakpoints then try running and see if it works.

Stone Preston
Stone Preston
42,016 Points

he actually adds that line of code in the next video at the 1:42 mark. I watched the video you created the forum post from and dont see anywhere where the lack of that method would case an error since he does not call it/define it until the next video. Did you skip a video perhaps?

Thanks for your reply, but if you test it in the video when he does before the next video, you get (lldb) and instead of the output he shows in this video. I have not moved on from the video I linked. If you do this video and test it like he does in only this one, you will get the same issue.

Stone Preston
Stone Preston
42,016 Points

can you post a link to the specific video you were on?

I have NO idea what is going on, but without even using your code, I just ran the build again with what I did vide the video and it builds right. I did not change anything. What version of Xcode are you using?

Stone Preston
Stone Preston
42,016 Points

5.0. it really sounds like you had a breakpoint set which means the program was halting execution when it reached that point. breakpoints are created by clicking in the left side of the editor in the line numbers, so they are easy to add accidently

I went back and tried what you said on purpose, and it created the issue I was getting before. I'm not fond of breakpoints since they can happen so easy lol. I thought I coded it all wrong, thanks.

Stone Preston
Stone Preston
42,016 Points

yeah they are a common source of confusion. no worries