Re: NSString category question
Re: NSString category question
- Subject: Re: NSString category question
- From: m <email@hidden>
- Date: Thu, 6 Mar 2003 09:04:47 +0000
On Thursday, March 6, 2003, at 01:34 AM, Koen van der Drift wrote:
I made an NSString category that removes all white spaces from a
string. My
understanding is that a category is an extension of an existing class,
so I
assumed I can use it as follows:
NSString* myString = [myTextView string]; // or some other
initialization
[myString removeWhiteSpace];
However, this doesn't change myString, it only works if I do:
myString = [myString removeWhiteSpace];
Maybe I misunderstand something about categories, or is the way it is
supposed to work?
That's how it is supposed to work.
Looking at your implementation for removeWhiteSpace, nowhere do you
actually change the receiver (i.e. myString, or 'self' if referenced
inside removeWhiteSpace). And even if you had, it would be an error;
NSStrings are non-mutable. That is, once created they don't change.
_murat
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.