Another approach is to create a dictionary before setting titleTextAttributes . It just avoids you otherwise, which would be more useful in cases where you would like to set additional parameters, also using fault-tolerant initializers. For instance:
var attributes : [NSObject : AnyObject] = [NSForegroundColorAttributeName : UIColor.whiteColor()] if let font = UIFont(name: "Helvetica", size: 20) { attributes[NSFontAttributeName] = font } if let someData = NSData(contentsOfFile: "dataPath") { attributes["imageData"] = someData } self.myObject.attributes = attributes
source share