Re: C string conversions?
Re: C string conversions?
- Subject: Re: C string conversions?
- From: Charilaos Skiadas <email@hidden>
- Date: Thu, 14 Jul 2005 08:55:38 -0500
On Jul 14, 2005, at 8:05 AM, Luc Vandal wrote:
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?
That depends on what it's retain count is at the moment. If you
inited or retained it, or if for any other reason its retain count is
non-zero, then it will not be deallocated.
What happens though is that any local variables you were using to
refer to those objects in the method don't refer to them any more.
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...
There is a difference between deallocate and release. You should be
releasing any instance variables. Whether they will get deallocated
or not is not your concern.
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:
@gmail.com
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:
40math.uchicago.edu
This email sent to email@hidden
Haris
_______________________________________________
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