I have a UITableView , and I would like to display the text of each row using different colors within the same row.
I tried this code trying to translate from Obj-C, but I can't work it
let object = self.fetchedResultsController.objectAtIndexPath(indexPath) as NSManagedObject var attrString: NSMutableAttributedString = NSMutableAttributedString(string: object.valueForKey("example1")!.description) attrString.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: NSMakeRange(0, attrString.length)) var stringToCell:String = String(format: "%@ %@", attrString, object.valueForKey("example2")!.description) cell.textLabel?.text = stringToCell
Conclusion of all this 
where the number 34 corresponds to object.valueForKey("example1")!.description , so the problem is that the number is not red, and the second part ( object.valueForKey("example2")!.description ) is replaced by { .
If you leave this piece of code in relation to NSAttributedString , the text of the line will be displayed correctly.
r4id4 source share