Re: NSTextView/NSMutableArray problem!
Re: NSTextView/NSMutableArray problem!
- Subject: Re: NSTextView/NSMutableArray problem!
- From: Marco Binder <email@hidden>
- Date: Tue, 27 May 2003 16:38:26 +0200
Retain / release is not the problem. NSMutableArray would retain any
object you add to it, so you dont have to worry about that.
Furthermore, if it was a problem of the object being released, you d
get a crash!
The point is, that, as the documentation that Greg quoted states, the
[NSText string] method returns a pointer to the actual contents of the
NSTextView, NOT a newly allocated NSString object. As you now alter the
contents of the NSTextView, obviously also the contents this pointer
points at changes. So if you delete the textviews content and try
"pasting" the content of the pointer you previously stored in your
array, nothing will be "pasted" just because the string this pointer
point at is now empty!
This is a common point of confusion when the type of the data returned
is of a mutable kind (then, you should always COPY to get a
"snapshot"). In this case, this issue does not come into mind right
away, because the returned type is an "unmutable" NSString which in
fact CAN be altered by the text system (the backing store). Tricky....
Marco
Am Dienstag, 27.05.03 um 11:13 Uhr schrieb Greg Hulands:
I don't know exactly why it would loose the string because an NSArray
increases the retain count. My rule of thumb is that if a NS class
returns a basic object like NSString or NSNumber then I just copy it
first, that way I know I own the object and not another part of the
system.
From the docs of NSText the super class of NSTextView
Returns the characters of the receiver's text. For performance reasons,
this method returns the current backing store of the text object. If
you want to maintain a snapshot of this as you manipulate the text
storage, you should make a copy of the appropriate substring.
Greg
On Tuesday, May 27, 2003, at 05:31 PM, Peter Karlsson wrote:
Hi Greg!
Yes, that was the problem, can you please explain this a little
futher. Why was the string not released when I used a NSTextField for
example?
Thanks a lot :-)
Peter
From: Greg Hulands <email@hidden>
To: "Peter Karlsson" <email@hidden>
CC: email@hidden
Subject: Re: NSTextView/NSMutableArray problem!
Date: Tue, 27 May 2003 17:22:10 +1000
It is possible that the string passed is getting released. Have you
tried
[myMutableArray replaceObjectAtIndex: 0 withObject:[[myTextViewOutlet
string] copy]];
HTH,
Greg
On Tuesday, May 27, 2003, at 04:46 PM, Peter Karlsson wrote:
Dear list!
I have a strange bug in my code, look at the following code
snippet...
// This works!!!
[myTextViewOutlet setString:@"Cocoa"];
// This works!!!
[myMutableArray replaceObjectAtIndex: 0 withObject:[myTextViewOutlet
string]];
// But not this!!!
[myTextViewOutlet setString:[myMutableArray objectAtIndex:0]];
Can someone tell me why the last line don't work with a NSTextView
please? I get no errors and the TextView is empty after the code is
executed, I was expecting "Cocoa" in the TextView as he result. It
works if I use a NStextField like this.
[myTextFieldOutlet setStringValue:[myMutableArray objectAtIndex:0]];
Peter
_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE*
http://join.msn.com/?page=features/virus
_______________________________________________
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.
_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8.
http://join.msn.com/?page=features/junkmail
_______________________________________________
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.
--
|\ /| email@hidden
http://www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________
_______________________________________________
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.