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 trialRodrigo Chousal
16,009 PointsI don't know what I'm doing wrong...
Instructions: Let's create a base class called 'Gem'. In 'Gem.h' define a class named 'Gem' which is a subclass of 'NSObject'.
My code:
@class Gem;
@interface Gem : NSObject;
@end
10 Answers
Thomas Nilsen
14,957 PointsTwo things:
1) No need for '@class Gem;' 2) drop the semicolon after NSObject
Other than that, it is correct.
RASHU BHATNAGAR
Courses Plus Student 2,669 PointsHi Rodrigo,
You will learn about that later but for now...
when we create a property then we give it two attributes
- nonatomic (when we are working in a non multithreaded environment)
- strong (when we have a parent child relationship, the the parent class will have a strong reference to its child class). Also, to my understanding, strong attribute will tell the compiler to store the value of the object ( to which strong attribute is defined ) as long as the property exists.
RASHU BHATNAGAR
Courses Plus Student 2,669 Pointswhen we declare a property then we give it two attributes...
strong- Every property or variable needs to be stored in the memory. So, defining the property as a strong attribute means that the object assigned to a property will not be destroyed unless we define it to be nil( or do not need it any more). Once the compiler comes across a line in which the nil value has been assigned to the property , then it will be removed (destroyed) from the computers memory other wise it will be stored and kept in the memory.
nonatomic- when we work in a multithreaded environment ( where more than one task are being executed at one time) then we define the properties as nonatomic.... We usually on a daily basis would be working on app which would be compliant to a multithreaded environment . In this more than a single task is happening at the same time and if needed then that task can access the property.
I hope I am able to satisfy your question....
Emmanuel Darmon
6,115 PointsYeah, didn't get what does (nonatomic, strong) mean?
Rodrigo Chousal
16,009 PointsWhat about this? Instructions: Finally, we have a class named 'Bling' which needs to have a property called 'ruby'. Switch over to 'Bling.h' and add a property named 'ruby' that belongs to the class 'Ruby'.
My Code:
@interface Bling : NSObject
@property Ruby *Ruby;
@end
Thomas Nilsen
14,957 PointsThat is correct (almost) - only thing you're missing is (nonatomic, strong) after property, and a SMALL r in *ruby
Patrick Donahue
9,523 Points@property(nonatomic, strong) Ruby *ruby;
You forgot to alloc memory.
Rodrigo Chousal
16,009 PointsWhat does (nonatomic, strong) mean?
Emmanuel Darmon
6,115 PointsThanks A LOT for your great answer Rashu!
Wren Howell
3,582 Pointswhat do you type in for part 2? I am confused!