NSAttributedString initWithData: not available

I am working in xCode on a Mac app. I have a string with HTML in it. I want to convert this to NSAttributedString. I see many references to using initWithData: including the Apple Documentation.

When I enter this code:

[NSAttributedString alloc]initWith

xCode shows no completion for initWithData:


If I copy and paste the complete line from posts I see to accomplish this, I am told that initWithData: does not exist.

Why is this?

Deployment target is :10.10

Accepted Reply

It all works for me. When I go to the definition of initWithData, I see it's added in a NSAttributedString category declared in AppKit, so make sure you import AppKit and not just Foundation. (This different import is documented on the web page for initWithData:… . This "splitting" of NSAttributedString is necessary because it depends on declarations outside of Foundation.)

Replies

Interesting, select NSAttributedString and do 'goto definition', InitWithData is not there.


there are three init methods:


- (instancetype)initWithString:(NSString *)str;

- (instancetype)initWithString:(NSString *)str attributes:(nullable NSDictionary<NSString *, id> *)attrs;

- (instancetype)initWithAttributedString:(NSAttributedString *)attrStr;

same issue using initWithHTML:

It all works for me. When I go to the definition of initWithData, I see it's added in a NSAttributedString category declared in AppKit, so make sure you import AppKit and not just Foundation. (This different import is documented on the web page for initWithData:… . This "splitting" of NSAttributedString is necessary because it depends on declarations outside of Foundation.)

.

thanks, I had just figured that out. had to import AppKit