SWIFT: +[CATransaction synchronize] called within transaction while decoding HTML entities
Asked Answered
A

1

3

I am making an app that fetches JSON content of a blog. The titles of the blog articles are shown in tableView.

The titles fetched were HTML encoded. So I decoded them using this code

func configureCell(cell: UITableViewCell, atIndexPath indexPath: NSIndexPath) {
    let object = self.fetchedResultsController.objectAtIndexPath(indexPath) as NSManagedObject

    var encodedString = object.valueForKey("title")!.description
    var encodedData = (encodedString as NSString).dataUsingEncoding(NSUTF8StringEncoding)
    var attributedOptions = [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType]
    var attributedString = NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil, error: nil)

    var decodedString = attributedString.string
    cell.textLabel?.text = decodedString

    // cell.detailTextLabel?.text = object.valueForKey("publishedDate")!.description
}

I could accomplish the decoding and the titles are displayed in the simulator perfectly. But the console shows this error ThisIsMe[6837:2029906] +[CATransaction synchronize] called within transaction 4 times. There is no other error in the code and al other functions work well.

pls help

Abad answered 11/2, 2015 at 15:23 Comment(1)
I also has the same error with NSAttributedString and HTML.Orvilleorwell
A
1

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

Abad answered 13/2, 2015 at 7:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.