uitextview - objective c inserting nil object from dictionary? -


i trying convert html attributedtext , store inside of uitextview. keep getting error

[__nsplaceholderdictionary initwithobjects:forkeys:count:]: attempt insert nil object objects[0]

i have checked values of dictionaries using , not nil, don't see problem is.

the attributed text generated , has value "your message here" in red text expected but, when try insert in line tx.attributedtext = attrstring; error.

  uitextview *tx =[[uitextview alloc]init];   [tx setreturnkeytype:uireturnkeydone];   [tx settag:1];   tx.delegate = self;     nsstring *htmlstring = @"<bold>test html</bold>";     nsdictionary *options = @{nsdocumenttypedocumentattribute: nshtmltextdocumenttype};    nsattributedstring *attrstring = [[nsattributedstring alloc] initwithdata:[htmlstring datausingencoding:nsutf8stringencoding]       options:options       documentattributes:nil       error:nil];    tx.attributedtext = attrstring;   return tx; 

edit: have simplified code,i have removed web request , inserted plain html. no matter inserted there, still same error

this raw value of htmlstring: may have messed in pasting value

"<!doctype html public "-//w3c//dtd html 4.01//en" "http://www.w3.org/tr/html4/strict.dtd"><html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta http-equiv="content-style-type" content="text/css"><title></title><meta name="generator" content="cocoa html writer"><style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px ".sf ui text"; color: #ff0000; background-color: #ffffff}span.s1 {font-family: ".sfuitext-regular"; font-weight: normal; font-style: normal; font-size: 14.00pt; text-decoration: line-through}</style></head><body><p class="p1"><span class="s1">your message here!</span></p</body></html>""

options :

[0] (null)  @"documenttype" : @"nshtml"  

attrstring :

`attrstring nsconcreteattributedstring *    @"hi test html" 

with attributes nsrlearray * 0x7fa0fd8053a0 0x00007fa0fd8053a0

inside of nsobject of isa class nsrlearray 0x000000010a03ede8

for reason, code above works fine if it not run on main thread had pass textview function , convert html attributedtext within it

    - (uitextview *)requestmessagereply:(uitextview*)textview {    nsmutableurlrequest *request = [[nsmutableurlrequest alloc] init];   [request sethttpmethod:@"get"];   [request seturl:[nsurl urlwithstring:@"http://lurl"]];    nserror *error = [[nserror alloc] init];   nshttpurlresponse *responsecode = nil;    nsdata *oresponsedata = [nsurlconnection sendsynchronousrequest:request returningresponse:&responsecode error:&error];    if([responsecode statuscode] != 200){     nslog(@"error getting http status code %li", (long)[responsecode statuscode]);      }    nsstring * responsestring = [[nsstring alloc] initwithdata:oresponsedata encoding:nsutf8stringencoding];    nsdata *jsondata = [responsestring datausingencoding:nsutf8stringencoding];    nsdictionary *json = [nsjsonserialization jsonobjectwithdata:jsondata options: nsjsonreadingmutablecontainers error:nil];     //  nsstring *htmlstring = [self requestmessagereply];   nsstring *htmlstring = (nsstring *)json[@"message"];   //(nsstring *)json[@"message"]   nsdictionary *options = @{nsdocumenttypedocumentattribute: nshtmltextdocumenttype,nscharacterencodingdocumentattribute: @(nsutf8stringencoding)};    nsattributedstring *attrstring = [[nsattributedstring alloc] initwithdata:[htmlstring datausingencoding:nsutf8stringencoding]                                                                     options: options                                                          documentattributes:nil error:nil];   textview.attributedtext = attrstring;   return textview; } 

Comments