Skip to content

Instantly share code, notes, and snippets.

@natebirkholz
Last active April 12, 2017 23:38
Show Gist options
  • Save natebirkholz/aff9a124b2a71a492d00c7744800be99 to your computer and use it in GitHub Desktop.
Save natebirkholz/aff9a124b2a71a492d00c7744800be99 to your computer and use it in GitHub Desktop.
let attributes = [ NSForegroundColorAttributeName : self.view.tintColor ]
let attributedString = NSAttributedString(string: NSLocalizedString("Sign In", comment: ""), attributes: attributes)
warns: (Expression implicitly coerced from 'UIColor?' to Any)
right way:
let attributes: [ String : UIColor ]
if let maybeAttributes = [ NSForegroundColorAttributeName : self.view.tintColor ] {
attributes = maybeAttributes
} else {
assertionFailure("self.view.tintColor is nil")
}
how it will be:
let attributes = [ NSForegroundColorAttributeName : self.view.tintColor! ]
let attributedString = NSAttributedString(string: NSLocalizedString("Sign In", comment: ""), attributes: attributes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment