Re: Does retain not work on ids?
Re: Does retain not work on ids?
- Subject: Re: Does retain not work on ids?
- From: Andy Lee <email@hidden>
- Date: Mon, 23 May 2005 22:50:02 -0400
On May 23, 2005, at 10:33 PM, Ken Tozier wrote:
Unless there's a compelling reason not to (and I can't think of one
offhand), you might want to consider using an object rather than a
struct.
The problem with an object was that it introduced a lot of extra steps
inside the code calling accessor methods for NSNumbers, converting the
numbers to floats etc it is much easier to just extract all this stiff
at initialization and access them using properties.xxx format. None of
the fields are visible outside the class so it just seems like a waste
of time to do all that accessor/conversion stuff.
You don't need to use NSNumbers; an object can have floats as ivars.
You may be thinking of the methods that read plists and generate
collection objects containing NSNumbers. But you don't have to use
plists. You could use a properties.xxx format and set your object's
ivars to floats and ints.
If your object is only for internal use, you can make the ivars public:
@interface UIObjectProperties : NSObject
{
@public
float temperature;
id data;
}
@end
...
float theTemp = myUIOP->temperature;
id theData = myUIOP->data;
This saves you the hassle of writing accessors for the scalar ivars.
But I would recommend writing setter methods for the object ivars so
they can be properly retained, and balancing the -retain calls with
-release calls in -dealloc. You have to balance your retains and
releases anyway, so you might as well use the standard Cocoa idiom for
doing so.
--Andy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden