Mac NSCFString? (NSTextView subclass)

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
599
0
West-Europe
What is NSCFString? I can't find anything useful about it in the documentation, developer.apple and google, but everyone has questions about it.

My problem with it is that I get such a string in my NSTextView subclass in the method insertText:.

I was expecting NSString or NSAttributedstring (or their mutable brothers and sisters), not NSCFString.

Where is the API for this beast? How am I supposed to (correctly) use it.
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
1
Portland, OR
What is NSCFString? I can't find anything useful about it in the documentation, developer.apple and google, but everyone has questions about it.

My problem with it is that I get such a string in my NSTextView subclass in the method insertText:.

I was expecting NSString or NSAttributedstring (or their mutable brothers and sisters), not NSCFString.

Where is the API for this beast? How am I supposed to (correctly) use it.
It is a private class implementing NSString's API. See http://www.cocoadev.com/index.pl?ClassClusters and http://www.cocoadev.com/index.pl?TollFreeBridging

<edit>
As for why NSTextView would complain about it... I'm really not sure. It shouldn't. My suspicion would be that something else is wrong and it's just giving an incorrect error message.
</edit>
 

Soulstorm

macrumors 68000
Feb 1, 2005
1,887
1
NSCFString errors should not appear when using Cocoa. Perhaps some code you are using will help us find the problem.
 

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
599
0
West-Europe
It is a private class implementing NSString's API. See http://www.cocoadev.com/index.pl?ClassClusters and http://www.cocoadev.com/index.pl?TollFreeBridging

<edit>
As for why NSTextView would complain about it... I'm really not sure. It shouldn't. My suspicion would be that something else is wrong and it's just giving an incorrect error message.
</edit>
Thanks for the links.

As for the code:
What needs to be done, depends on the class of aString. Seeing "id" I expected an attributed or non-attributed string. Whatever I do in the NSTextView, I always get an NSCFString ([aString className]).

My original code was based on wrong assumptions, but everything seems to work now. The error that led me to NSCFString came from [aString string], expecting in some cases an NSAttributedString, while I only needed the string itself.
 

Eraserhead

macrumors G4
Nov 3, 2005
10,410
10,890
UK
I think you need to do code similar to the following.

Code:
[INDENT]
if([initialString respondsToSelector:@selector(string)]){[INDENT][textBox setStringValue:[initialString string]];[/INDENT]}else{[INDENT][textBox setStringValue:initialString];[/INDENT]}[/INDENT]
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.