I come from a fairly strong background in C ++, but I can definitely remember when I started, it was hard for me to grab onto the concept until I found a way to associate it with physical objects.
The class and object of a word that you can use is almost interchangeable. Think of the object as a container, as a bucket. The word bucket will be your class. This is the name that you point to the type of object that you have.
The bucket has a specific purpose ... to carry something. It could be water ... or sand. Therefore, perhaps you want to fill the bucket. This will be what you do with the bucket, so in objective-c this will be your method. You can write something like:
- (void) fillWith:(elementType)something;
So, in this case, “something” may be something that represents the object that you want to fill with your bucket.
Your class might look like this:
typedef enum items { CRAYONS, MARKERS, SAND, WATER } elementType; @class Bucket { elementType item; } - (void) fillWith:(elementType)something; @end
Here is one link for some objective-c samples. Also try the apple development center.
source share