Re: C string conversions?
Re: C string conversions?
- Subject: Re: C string conversions?
- From: Michael McCracken <email@hidden>
- Date: Wed, 13 Jul 2005 13:53:59 -0700
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:
>
> 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