Any stack variable (int, float, etc) won't be declared as a pointer. Recall that a variable containing a * indicates that it is, in fact, some address in memory that is being pointed to (hence a pointer). If we recall, then, that memory consists of a "stack" and a "heap" - the pointer sits on the stack and points to the heap. Objects are pointers, things that aren't Objects (as in, instances of a class) in C-based languages aren't pointers. I would strongly advise reviewing either and introduction to C or to Objective-C before delving much into Cocoa as these sort of things are very much a pre-requisite to understanding the behavior of the code you're writing. Similarly, since (I'm guessing) this is a new project I'd advise targeting Leopard and higher and using @property declarations for your class members. If you're OK with going 64bit only (or iPhone), you can go a step further and eliminate your variable declarations entirely and just create @property declarations for use with "non-fragile instance variables" (you probably don't need to know what that is right now aside from it being a Good Thing™).

-rob.

On Dec 23, 2008, at 2:19 AM, Roland King wrote:

it looks as if you your class variable someInt declared as (int*), why? If you want an int, someInt should be declared as an int.

aaron smith wrote:

Sorry for the total newb here. What's the right way to create
getters/setters for int's? Without the compiler warning about them?

I've been trying:

-(void)setSomeInt:(int)theInt
{
  someInt=theInt;
}

-(int)someInt
{
  return someInt;
}

Then calling it..
[myObj setSomeInt:1];

Usually I get two warnings:
"warning: assignment makes pointer from integer without cast"
"warning: return makes integer from pointer without cast"

From those two warnings, I was thinking these updates do the trick:

-(void)setSomeInt:(int)theInt
{
  someInt=(int *)theInt;
}

-(int)someInt
{
  return (int)someInt;
}

Calling it:
[myObj setSomeInt:(int *)1];

Is this the correct way?
Thanks all..
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org

This email sent to [email protected]


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/rob%40pinchmedia.com

This email sent to [email protected]

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to