Unrecognized selector exception #246

Closed
fox-a opened this Issue Nov 26, 2012 · 18 comments

Projects

None yet
@fox-a
fox-a commented Nov 26, 2012

I create NSAttributedString following way:


    NSData *data = [htmlText dataUsingEncoding:NSUTF8StringEncoding];
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithHTMLData:data documentAttributes:NULL];

Then set UIButton's AttributedTitle with string from above. App compiles successfully but at run-time I get following error:
NSAttributedString


 -[__NSCFType lineBreakMode]: unrecognized selector sent to instance 0x9918e60
 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType lineBreakMode]: unrecognized selector sent to instance 0x9918e60'
*** First throw call stack:
(0x287d012 0x1dd1e7e 0x29084bd 0x286cbbc 0x286c94e 0x2cbaea1 0x2cbaa56 0xb89914 0xeb53f9 0xeb55ed 0xeb5593 0xeb8cf3 0xb8892a 0xeb8beb 0x281f8fd 0xeb8b96 0x281f8fd 0xeb8b96 0xeb03f3 0x743733 0xeb03c8 0xeb030c 0x1de56b0 0x183ffc0 0x183433c 0x1834150 0x17b20bc 0x17b3227 0x17b38e2 0x2845afe 0x2845a3d 0x28237c2 0x2822f44 0x2822e1b 0x2c107e3 0x2c10668 0x97865c 0x898c 0x2d05)
libc++abi.dylib: terminate called throwing an exception

This is the htmlText value:
<html><p>Sample text</p></html>

@odrobnik
Collaborator

Current DTCoreText is not compatible with iOS 6 UIKit controls.

@fox-a
fox-a commented Nov 29, 2012

Thanks for info.
Are there any plans to add this supports?
Could you note that in readme so others wouldn't get confused like I did?

@odrobnik
Collaborator

There is a new option that makes use of iOS 6 attributes and the result is compatible with UITextView. See the iOS 6 sample.

@odrobnik odrobnik closed this Dec 12, 2012
@krzyzanowskim
Contributor

Just got this on iOS 7.1 when using NSAttributedString with UILabel

@krzyzanowskim
Contributor

If using with UITextView then I get
-[__NSCFType textBlocks]: unrecognized selector sent to instance 0xb45cac0

@odrobnik
Collaborator

Add the iOS6-support attribute to the parsing options.

@krzyzanowskim
Contributor

But it's on iOS 7 (??). Ok after I enabled iOS6 support it is working. Why it is so ?

@odrobnik
Collaborator

it's an old name. it essentially means to use the NS-style attributes when building the attributed string, instead of the old CoreText-style attributes which are incompatible with UIKit.

@bentford

I also got this error on iOS7. It would be nice to enable this mode by default or at least have a compiler warning on iOS7.

@odrobnik
Collaborator

That's nothing to check for at compile time. UIKit supports less features of HTML than our DT views do and while this is the case we cannot make the NS-style attributes the default. But if somebody submits a good pull request with a reasonable solution then I am willing to entertain it.

@bentford

I guess what I'm actually suggesting is that the default option shouldn't crash when using UIKit views. Or possibly rename the parse option to mention the fact that it supports UIKit views when used (and that without the option, the attributed string will may only support DT views.)

The problem is both the crash and fix are slightly obtuse.

Here is the error I was getting:

-[__NSCFType set]: unrecognized selector sent to instance)

The fix: using the iOS6 attributes, doesn't seem like an obvious fix. The only way to figure out what to do is googling and reading this ticket.

@m1entus
Contributor
m1entus commented Apr 4, 2015

It is also happening on iOS8
-[__NSCFType lineBreakMode]: unrecognized selector sent to instance
-[__NSCFType textBlocks]: unrecognized selector sent to instance

And attributed string parsed by DTCoreText:

  The average health insurance rate increase next year will be about 6 percent in New York State.
 
State regulators today set the rates for 2015 after reviewing proposals from insurers, which requested an average increase of about 13 percent. {
      CTForegroundColor = "<CGColor 0x79f7e340> [<CGColorSpace 0x79e5bbc0> (kCGColorSpaceDeviceGray)] ( 0 1 )";
      NSFont = "<UICTFont: 0x7b2edca0> font-family: \"Avenir-Book\"; font-weight: normal; font-style: normal; font-size: 14.00pt";
      NSParagraphStyle = "<CTParagraphStyle: 0x7b2ee2d0>{base writing direction = -1, alignment = 4, line break mode = 0, default tab interval = 36\nfirst line head indent = 0, head indent = 0, tail indent = 0\nline height multiple = 0, maximum line height = 0, minimum line height = 0\nline spacing adjustment = 0, paragraph spacing = 14, paragraph spacing before = 0\n}";
  }Westhill Healthcare Consulting{
      CTForegroundColor = "<CGColor 0x7b2ee7f0> [<CGColorSpace 0x79f68060> (kCGColorSpaceDeviceRGB)] ( 0 0 0.933333 1 )";
      CTForegroundColorFromContext = 1;
      DTGUID = "BF2C7C1F-16FE-4DFC-B0CC-19E761FFE170";
      DTLinkHighlightColor = "UIDeviceRGBColorSpace 1 0 0 1";
      NSFont = "<UICTFont: 0x7b2edca0> font-family: \"Avenir-Book\"; font-weight: normal; font-style: normal; font-size: 14.00pt";
      NSLink = "http://www.westhillinsuranceconsulting.com/blog/new-york-regulators-slash-health-insurance-rates-2015/";
      NSParagraphStyle = "<CTParagraphStyle: 0x7b2eedd0>{base writing direction = -1, alignment = 4, line break mode = 0, default tab interval = 36\nfirst line head indent = 0, head indent = 0, tail indent = 0\nline height multiple = 0, maximum line height = 0, minimum line height = 0\nline spacing adjustment = 0, paragraph spacing = 14, paragraph spacing before = 0\n}";
      NSUnderline = 1;
  }


Original attributed string parsed by iOS8 NSAttributed HTML extension:

The average health insurance rate increase next year will be about 6 percent in New York State.
 
State regulators today set the rates for 2015 after reviewing proposals from insurers, which requested an average increase of about 13 percent. {
    NSColor = "UIDeviceRGBColorSpace 0 0 0 1";
    NSFont = "<UICTFont: 0x7ab8caf0> font-family: \"Avenir-Book\"; font-weight: normal; font-style: normal; font-size: 14.00pt";
    NSKern = 0;
    NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n), DefaultTabInterval 36, Blocks (null), Lists (null), BaseWritingDirection 0, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
    NSStrokeColor = "UIDeviceRGBColorSpace 0 0 0 1";
    NSStrokeWidth = 0;
}Westhill Healthcare Consulting{
    NSColor = "UIDeviceRGBColorSpace 0 0 0.933333 1";
    NSFont = "<UICTFont: 0x7ab8caf0> font-family: \"Avenir-Book\"; font-weight: normal; font-style: normal; font-size: 14.00pt";
    NSKern = 0;
    NSLink = "http://www.westhillinsuranceconsulting.com/blog/new-york-regulators-slash-health-insurance-rates-2015/";
    NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n), DefaultTabInterval 36, Blocks (null), Lists (null), BaseWritingDirection 0, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
    NSStrokeColor = "UIDeviceRGBColorSpace 0 0 0.933333 1";
    NSStrokeWidth = 0;
    NSUnderline = 1;
}

Maybe you should think to change DTUseiOS6Attributes to more intuitive name like, without googling i would never found out it.
 

@lekksi
lekksi commented Jun 24, 2015

+1 happening on iOS 8.3

@yas375
yas375 commented Sep 24, 2015

Just got -[__NSCFType lineBreakMode]: unrecognized selector sent to instance ... on iOS9 using DTCoreText 1.6.16. I've tried to remove DTUseiOS6Attributes from the list of options passed into DTHTMLAttributedStringBuilder#initWithHTML:options:documentAttributes:. I thought I don't need this since I'm not targetting iOS6. What's the meaning of this option? Why is it required? Do you need more info to debug the issue?

@ryanmaxwell

@yas375 I think the option is a bit of a misnomer, it means iOS6 and later.

So you must set the option to YES / true

let str = NSMutableAttributedString(HTMLData: data, options: [DTUseiOS6Attributes: true], documentAttributes: nil)
@chikuba
chikuba commented Dec 1, 2015

This should really be made a default since noone is using iOS 5 anymore

@aaronlwilson

A simple and permanent fix is to find the file DTCoreTextConstants.m and look for the line:
BOOL ___useiOS6Attributes = NO;

change that bool to YES, and you can use the NSAttributedText methods without having to pass an object dictionary.

@bartoszhernas

Thanks @ryanmaxwell, this solves the issue.

Shouldn't it be already set to true as default?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment