Re: Re Re: String variables in classes

2011-01-02 Thread Graham Cox
On 03/01/2011, at 10:17 AM, Brian Durocher wrote: > This line of code seems to work for exactly what I was looking for: > >temp = [[temp stringByAppendingFormat:@" %@ %@ \n", input1, input2] > retain]; Except it's quite wrong from a memory management point of view. As well as the excellen

Re: Re Re: String variables in classes

2011-01-02 Thread Charles Srstka
On Jan 2, 2011, at 6:10 PM, Stephen J. Butler wrote: > - Charles asks 'why the @""' and I can answer that question: because > you couldn't figure out another way to call stringByAppendingFormat: > could you? The answer is that in this case you should be calling > +[NSString stringWithFormat:]. How

Re: Re Re: String variables in classes

2011-01-02 Thread Stephen J. Butler
On Sun, Jan 2, 2011 at 5:17 PM, Brian Durocher wrote: > #import > > @interface Calculator : NSObject > { >    double accumulator; >    NSString* caption; >    NSString* name; >    NSString* temp; > } > > - (id) init; > - (void) setAccumulator:(double) n; > - (void) printAccumulator; > > - (NSStri

Re: Re Re: String variables in classes

2011-01-02 Thread Charles Srstka
On Jan 2, 2011, at 5:17 PM, Brian Durocher wrote: > Thank you guys for your assistance. I come from a C++ background and > have done embedded design in ASM. But this way of working and > particularly the framework is very new to me. I understand what you are > saying, but the literature I am readi

Re: Re Re: String variables in classes

2011-01-02 Thread Charles Srstka
On Jan 2, 2011, at 5:17 PM, Brian Durocher wrote: > - (void) setCaption: (NSString*)input > { >[caption autorelease]; >caption = [input retain]; > } For this (and for the rest of the NSString ivars), it’s generally better to use -copy rather than -retain. The reason for this is that it i