Following the great example of How do I decode HTML entities in swift? I have managed to decode a HTML entity. However, running my app in iOS simulator causes no errors while testing it on a real device do.
I'm getting the following error:
Thread 1: EXC_BAD_ACCESS (code=1, address=0xc)
On this line:
let attributedString = NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil, error: nil)!
How do you go about solving this?
Probably you are not running the code in the main thread. I am not sure how it is working in the simulator. Anyway try putting that code in a main thread block like dispatch_async(dispatch_get_main_queue(), { let attributedString = NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil, error: nil) let decodedString = attributedString?.string })
It should work properly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.