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.
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
@interface Gem : NSObject @end
#import "Gem.h" @interface Ruby : Gem @end
#import "Ruby.h" @interface Bling : NSObject @property int ruby; @end
Gabe NadelTreehouse 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.
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?
Tommy Choe38,156 Points
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.