DTCoreText: Unrecognized selector exception

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>

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Comments: 21 (5 by maintainers)

Most upvoted comments

@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)

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

This should really be made default, still an issue in 2017.

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.

Add the iOS6-support attribute to the parsing options.