Re: string help
Re: string help
- Subject: Re: string help
- From: Chris Hanson <email@hidden>
- Date: Thu, 8 Sep 2005 08:51:07 -0700
On Sep 8, 2005, at 8:06 AM, Bob Sabiston wrote:
On Sep 7, 2005, at 7:15 PM, Chris Hanson wrote:
Where and how do you allocate commandString?
Well, I just set it to this value @"nocommand" in my Controller
init function. How should I allocate it instead?
You declared commandString as an NSMutableString but assigned a
constant string to it. You should allocate and assign a mutable
string to it.
Actually, I just tried
commandString = [NSMutableString initWithCapacity:255];
[snip]
then it does not seem to do anything. I am still foggy on how the
string allocation works.
String allocation is just like any other object allocation, with the
exception of constant strings. (You can treat those as singletons.)
So in this case, you want to use:
commandString = [[NSMutableString alloc] initWithCapacity:255];
You always need to allocate an object before initializing it.
Note also that you're not creating the equivalent of a Str255 here.
commandString can be of any length, you're just hinting that you
expect to need to 255 characters' worth of space.
-- Chris
_______________________________________________
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