help with strings

whitesaint

cocoa love
I have a textField with a string in it. How do i request or take that string so i can do somthing else with it? Thanks in advance.

-whitesaint
 
dunno if you want an answer to this now, it was two months ago and you have probably figured it out already. but for others, like me, who browse these forums in search of information, here is the answer to the question:

<tt>
// assume we have a NSTextField called "field"

NSString *str = [[field stringValue] retain];

// do things with the string

[field setStringValue:str];

[str release];
</tt>


I'm still not too good about memory management, so don't trust me on the retains and releases... I assume that [field stringValue] returns an autoreleased reference, is this right?

theo
 
From what I understand (and my memory management is as bad as yours, I'm sure), you don't need to send a retain message to [field stringValue] or send a release message to str because stringValue returns an autoreleased object. If you had created an NSString object via an alloc and an init, then you would need to retain and release it, but in this case the object gets deallocated when it goes out of scope... but I could be wrong.

F-bacher
 
Back
Top