NSCFString? (NSTextView subclass)

Discussion in 'Mac Programming' started by MrFusion, Oct 19, 2007.

  1. MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #1
    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.
     
  2. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #2
    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>
     
  3. Soulstorm macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #3
    NSCFString errors should not appear when using Cocoa. Perhaps some code you are using will help us find the problem.
     
  4. MrFusion thread starter macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #4
    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.
     
  5. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #5
    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]
    
     

Share This Page