Understanding pointers basics

Discussion in 'iOS Programming' started by doanelinde, Sep 2, 2009.

  1. doanelinde macrumors member

    Jul 24, 2009
    I have a basic understanding of pointers from C.

    One thing that confused me for a while in objc with pointers was the fact that there was no dereferencing character being used, but I wasn't aware that that was what was confusing me, if that makes sense!

    I think I've got a grip on that now.

    But I'm still having a lot of issues with pointers and variables.

    For instance I have a class with a list of properties, such as:
    	NSInteger atmID;
    	NSNumber *Latitude;
    	NSNumber *Longitude;
    	NSString *Add1; 
    	NSString *Add2;
    	NSString *Add3; 
    To me, this is a list of variables of different types. But there's some massive difference between the way the different types are working. And let's say I throw in a primitive C long there as well.

    So Latitude is a pointer to a variable of type NSNumber? But NSInteger isn't a pointer, and when I @property it, I can't retain it, I simply assign it.
    I've had no issues whatsoever working with the strings, but I have had issues working with integers and other variables.

    These are really confusing me, and to be honest I just don't know what questions to ask. I've looked around and found a lot of information on pointers but still can't get my head around them.

    Any help would be greatly appreciated, thanks in advance.
  2. robbieduncan Moderator emeritus


    Jul 24, 2002
    Look at the documentation for NSInteger: it's not a class: it's typedefed type. That is the difference.
  3. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    Also, the convention is to name your variables starting with a lower-case letter. Helps distinguish them from class names, which normally start with upper-case.
  4. doanelinde thread starter macrumors member

    Jul 24, 2009
    Yes, I looked at that before and from my understanding NSInteger is either a long or an int as from primitive c, depending on whether a 32 or 64bit variable is needed?

    But I still don't understand the difference between these variables and pointers.

    What's the difference between an NSString and an int as attributes of my object?

    The reason I have these in upper case is because the names have to match the elements from an XML file I'm parsing in.

    Thanks for the help!
  5. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    NSString is a class and int is a C primitive. The former is an Objective-C construct and the latter is a C construct. If that confuses you, perhaps avoid the C primitives and use NSNumber instead of int.
  6. Kingbombs macrumors member

    Jun 24, 2009
    maybe look at the relation of an array and a pointer, it may help you to understand them better

Share This Page