• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Arg, lmao question - (int)getters/setters.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Arg, lmao question - (int)getters/setters.


  • Subject: Re: Arg, lmao question - (int)getters/setters.
  • From: Robert Marini <email@hidden>
  • Date: Tue, 23 Dec 2008 11:10:36 -0500

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@hidden)

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:
This email sent to email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden

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

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

References: 
 >Arg, lmao question - (int)getters/setters. (From: "aaron smith" <email@hidden>)
 >Re: Arg, lmao question - (int)getters/setters. (From: Roland King <email@hidden>)

  • Prev by Date: Re: Cocoa-dev Digest, Vol 5, Issue 2199
  • Next by Date: Re: Network volume
  • Previous by thread: Re: Arg, lmao question - (int)getters/setters.
  • Next by thread: Re: Arg, lmao question - (int)getters/setters.
  • Index(es):
    • Date
    • Thread