Talk About Network

Google





Mac > Mac Programmer Help > strings
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 3690 of 3889
Post > Topic >>

strings

by Santa Claus <santa@[EMAIL PROTECTED] > Apr 3, 2008 at 05:09 PM

ok, it was suggested to me that i shouldn't use copies of strings as i 
do here

  [informationCenter sendCommand: [NSMutableString stringWithString: 
theString]];
  [lastCommand setString: [NSString stringWithString: theString]];
  [myCommandArray1 addObject: [NSString stringWithString: theString]];

according to my experience and testing, i've found out something 
dangerous about doing it your way.  here's an example:

  [theString setString: @[EMAIL PROTECTED]
"one"];
  [informationCenter sendCommand: theString];
  [lastCommand setString: theString];
  [myCommandArray1 addObject: theString];
  [theString setString: @[EMAIL PROTECTED]
"two"];

you would assume that "one" would be sent to the informationCenter, 
stored in lastCommand, and appended to myCommandArray1 and you would be 
correct however, when you set theString to "two" all the others will 
change as well (unless sendCommand already sent the command in which 
case IT won't be changed).  at the end of the process, you'd expect 
"one" to be the last item in myCommandArray1 and you'd be wrong.

now here's the question, how would you geniuses out there write what i 
wrote in a SAFE way (a way in which will not be changed in the manner i 
mentioned) and still not require the copying using stringWithString?
 




 4 Posts in Topic:
strings
Santa Claus <santa@[EM  2008-04-03 17:09:15 
Re: strings
Gregory Weston <uce@[E  2008-04-03 23:57:00 
Re: strings
Santa Claus <santa@[EM  2008-04-03 22:21:40 
Re: strings
Gregory Weston <uce@[E  2008-04-04 10:21:44 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 19:53:30 PST 2009.