SWIFT: +[CATransaction synchronize] called within transaction while decoding HTML entities
This problem occurred during decoding HTML entities, so i looked for another way to decode and used the following code:
func configureCell(cell: UITableViewCell, atIndexPath indexPath: NSIndexPath) {
let object = self.fetchedResultsController.objectAtIndexPath(indexPath) as NSManagedObject
let eTitle:NSString = object.valueForKey("title")!.description
let deTitle = eTitle.stringByDecodingHTMLEntities()
cell.textLabel?.text = deTitle
}
Earlier, the stringByDecodingHTMLEntities()
was missing. So I had taken this approach.
Note: To Get stringByDecodingHTMLEntities()
we need to import NSString+HTML.h, from here NSString category for HTML
How to display HTML text in TextView
This works for me. Remember that the NSAttributedString
constructor now throws
an NSError
object:
Swift 3:
do {
let str = try NSAttributedString(data: def.data(using: String.Encoding.unicode, allowLossyConversion: true)!, options: [NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType], documentAttributes: nil)
} catch {
print(error)
}
Swift 2.x:
do {
let str = try NSAttributedString(data: def.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!, options: [NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType], documentAttributes: nil)
} catch {
print(error)
}
Related Topics
Sharing Highscore with Social Media
How to Use the "Handler" of Uialertaction to Call Another Uialertaction
Running Swift Build in Terminal Leading to "Platform Path" Errors
How to Repeat Animation Forever in Swift (Huge_Valf)
Partial Application of 'Mutating' Method Is Not Allowed
Suppress Warnings from Dependencies with Swift Package Manager
Swift Build' on Terminal Throw 'Error: Root Manifest Not Found'
In Swift, How to Extend a Typealias
API Violation - Multiple Calls Made to -[Xctestexpectation Fulfill]
How to Select All Text in a Uitextfield Using Swift
Checking Conforms Protocol with Associatedtype in Swift
Nspredicate in Query from Array Elements
Swift: No Idea How to Get Back the Selected Value from a Popover to the Calling Controller