Re: C string conversions?
Re: C string conversions?
- Subject: Re: C string conversions?
- From: Luc Vandal <email@hidden>
- Date: Thu, 14 Jul 2005 09:05:22 -0400
I have a dumb question about 'init...'.
If I create an instance within a function, will the instance be
automatically deleted at the end of the function scope or do I need to
use release or autorelease?
I usually deallocate (release) members of the class when the class
instance is destroyed but assumed that every object I instantiate in a
function would be released at the end of the scope...
Luc
On 13-Jul-05, at 4:53 PM, Michael McCracken wrote:
Welcome, Charles.
any method that starts with 'init...' is an instance method, so you do
need to allocate an object first - in your case you want this:
[[NSAttributedString alloc] initWithString:[NSString
stringWithCString:cstringgoeshere]]
if NSAttributedString had a + attributedStringWithString: class
method, that'd do what you want, but it doesn't, so you have to do it
this way.
Note that since you've created an object and initialized it yourself,
you own it - It has a retain count of 1 now and you will have to
release or autorelease it or it will be a leak once you're no longer
using it.
A quick intro read might be in order - the conceptual docs are
definitely worth the time, and don't really take as long to read as it
seems:
http://developer.apple.com/documentation/Cocoa/Conceptual/
CocoaObjects/index.html
HTH,
-mike
On 7/13/05, Charles Turner <email@hidden> wrote:
Hi all-
New to Cocoa and the list, and of course had a question:
I have an instance method in an object I've written that has a C
string
as an argument. I need to store this in a TextStorage object,
currently
using appendAttributedString:
Any thoughts on conversion? Right now I'm trying:
[NSAttributedString initWithString: [NSString stringWithCString:
aString]]
but initWithString isn't a class method, so it looks like I would have
to create an instance of NSAttributedString...
Anyway, thanks in advance if anything strikes you.
Best,
Charles Turner
<email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
--
Michael McCracken
UCSD CSE PhD Candidate
research: http://www.cse.ucsd.edu/~mmccrack/
misc: http://michael-mccracken.net/blog/
_______________________________________________
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
_______________________________________________
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