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 Inheritance

How do I declare a property that belongs to another class?

I'm trying to declare a property called ruby that belongs to the class Ruby. But something with my syntax is wrong and the code doesn't go through

Gem.h
@interface Gem : NSObject

@end
Ruby.h
#import "Gem.h"

@interface Ruby : Gem

  @end
Bling.h
#import "Ruby.h"

@interface Bling : NSObject

  @property int ruby;

@end

3 Answers

Gabe Nadel
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Gabe Nadel
Treehouse Guest Teacher

Just the type of question that we love to see in the community!

So, just to be clear, do you want to:

1) Declare a property of TYPE ruby, that belongs to class Bling? or 2)Declare a property of TYPE int, named ruby, that belongs to class Bling?

It seems the description of your problem and the code you posted are aimed at two different things. You can also explain a bit about what you are trying to do with the project and that might help us give some guidance.

Hi Gabe,

Essentially I am trying to add a property named 'ruby' that belongs to the class 'Ruby'. How do I connect the property with the class Ruby?

Thanks!

Tommy Choe
Tommy Choe
38,156 Points

Hi Anna,

try moving "@property int ruby" from the Bling header file to the Ruby header file. That way you are declaring the accessor methods in the Ruby class and you can access it from the Bling class. Hopefully that helps.