Note that there are some explanatory texts on larger screens.

plurals
  1. POEncoding NSAttributedString Throws Error
    primarykey
    data
    text
    <p>Based on the accepted answer to <a href="https://stackoverflow.com/questions/2626667/saving-custom-attributes-in-nsattributedstring/" title="this question">this question</a> I wrote the following code:</p> <pre><code>NSData* somedata; somedata=[NSKeyedArchiver archivedDataWithRootObject:ts]; </code></pre> <p>where ts is an NSAttributedString that is populated with some text and some attributes (colors, in this case).</p> <p>When I execute this code, I receive this error:</p> <pre><code>*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType encodeWithCoder:]: unrecognized selector sent to instance 0x6eb5b90' </code></pre> <p>I'm new to the NSCoder arena, but the answer to the aforementioned question made it seem like this is all I have to do. Is it? Did I miss something?</p> <hr> <p>EDIT: </p> <p>The unrecognized selector in this case is being sent to a color attribute in the NSAttributedString. When I initialize the string like so:</p> <pre><code>NSAttributedString *ts = [[NSAttributedString alloc] initWithString:text attributes:self.currentAttributeDictionary]; </code></pre> <p>The dictionary is built like so:</p> <pre><code>self.currentAttributeDictionary=[NSDictionary dictionaryWithObjectsAndKeys: [self.currentColor CGColor],(NSString*)kCTForegroundColorAttributeName, nil]; </code></pre> <p>And an NSLog of the dictionary yields this:</p> <pre><code>New dictionary is: { CTForegroundColor = "&lt;CGColor 0x6eb5b90&gt; [&lt;CGColorSpace 0x6e968c0&gt; (kCGColorSpaceDeviceRGB)] ( 1 1 0 1 )";} </code></pre> <p>The address of the CGColor, above, matches the address in the error message.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload