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

Rodrigo Chousal
Rodrigo Chousal
16,009 Points

I 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
Thomas Nilsen
14,957 Points

Two things:

1) No need for '@class Gem;' 2) drop the semicolon after NSObject

Other than that, it is correct.

Hi Rodrigo,

You will learn about that later but for now...

when we create a property then we give it two attributes

  1. nonatomic (when we are working in a non multithreaded environment)
  2. 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.

when we declare a property then we give it two attributes...

  1. 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.

  2. 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
Emmanuel Darmon
6,115 Points

Yeah, didn't get what does (nonatomic, strong) mean?

Rodrigo Chousal
Rodrigo Chousal
16,009 Points

What 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
Thomas Nilsen
14,957 Points

That is correct (almost) - only thing you're missing is (nonatomic, strong) after property, and a SMALL r in *ruby

Patrick Donahue
Patrick Donahue
9,523 Points

@property(nonatomic, strong) Ruby *ruby;

You forgot to alloc memory.

Rodrigo Chousal
Rodrigo Chousal
16,009 Points

What does (nonatomic, strong) mean?

Emmanuel Darmon
Emmanuel Darmon
6,115 Points

Thanks A LOT for your great answer Rashu!

Wren Howell
Wren Howell
3,582 Points

what do you type in for part 2? I am confused!