obj-c and . notation

zerorex

Registered
I've been programing in php and java for a while now, and I decided I wanted to take a whack at obj-c and cocoa. So far all looks good, but I have a question. I know that obj-c uses the
[reciever method:arg];
structure for messaging, but i ran across something in the learnign cocoa book i am working through that looks simmilar to this:

[reciever something.something.something];

I didnt think that cocoa use the . structure for anything. Is this just another way of getting to instance variables, or is this something else?

Also, Im not really familure with c programing beyond its implecations in java and such, thus I am not all that familure with pointers. I understand they are ment to be a pointer to the actual instance variable for the object, but I cant figure out when one is needed and when one is not.

for instance, I gather that variables of type int, bool, and other primitives dont need pointers, and that NSObject, or NSString would need a pointer, but what has confused me is that it seems that something like NSRange doesnt need a pointer... Im thinking taht possibly objects which are returned from methods invocations of other objects possibly dont need to be typed as a pointer, but im not sure.


Any help would be much apreciated.

Thanks,
Z
 

slur

Geek / Hedonist
This is a great overview of Objective-C:

http://developer.apple.com/techpubs/macosx/Cocoa/ObjectiveC/

You might find it especially useful to read up on C and C++ also. The dot operator in Objective-C is the same as that for C, and refers to members of a data structure. This illustrates how to access data in structures using the dot and arrow operators:

myStruct aStruct;
myStruct *aStructPtr = &aStruct;
int myData = aStruct.someInt;
int myOtherData = aStructPtr->someInt;
 

zerorex

Registered
slur,
You are a prince among men. Incodentaly, I was reading some c documentation to get a better grasp of pointers and ran across some information on structures, that combined with what you said has cleared the fog.

Thanks a mill,
Z
 

iconara

Registered
it was probably more like this:

Code:
[reciever method].something.something

where the method returns a C-struct, which uses dot-notation.

but you seem to have figured it out already


theo/iconara
 
Top