ios - Cannot invoke initializer for type 'NSAttributedString' with an argument list of type -
this question has answer here:
- convert html plain text in swift 5 answers
i followed example decode html values. to decode json parsed value: answered akashivskyy
i had code , getting following error:
let encodedstring = "the weeknd ‘king of fall’" let encodeddata = encodedstring.datausingencoding(nsutf8stringencoding)! let attributedoptions : [string: anyobject] = [ nsdocumenttypedocumentattribute: nshtmltextdocumenttype, nscharacterencodingdocumentattribute: nsutf8stringencoding ] let attributedstring = nsattributedstring(data: encodeddata, options: attributedoptions, documentattributes: nil, error: nil)! let decodedstring = attributedstring.string
error:
cannot invoke initializer type 'nsattributedstring' argument list of type '(data: nsdata, options: [string : anyobject], documentattributes: _, error: _)'
any appreciated suggest ay answer.
remove error
option nsattributedstring
initializer , add try
instead:
let attributedstring = try? nsattributedstring(data: encodeddata, options: attributedoptions, documentattributes: nil)
Comments
Post a Comment