Search code examples
swifthtml-entitiessynchronizecatransaction

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


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


Solution

  • 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