discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question about NSString...


From: Richard Frith-Macdonald
Subject: Re: question about NSString...
Date: Thu, 09 Jun 2005 05:58:42 +0100

On 2005-06-09 01:41:11 +0100 Lloyd Dupont <lloyd@nova-mind.com> wrote:

I have some weird problem...

[NSString alloc], when called a second time, seems to return the same id than the 1st call. is it thta alloc should not be used on string? or a bug in my code?

Neither .... that's normal behavior.

NSString is a class cluster ... it consists of several classes which are optimised for different types of string data, and when you call +alloc you get an instance of a general placeholder subclass. This is replaced by an instance of another subclass when you initialise it.

Similar things are done by many other classes.

The general rule is that when you call any initialiser method (ie an instance methoid whose name begins with 'init') you must expect it to return a different object from the receiver and must then use the new object rather than the old one.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]