0

The following code is throwing a warning for me after project is upgraded to Swift 5. Why is that? Can anyone tell me? why did they make it optional?

let attributes:[NSAttributedString.Key: Any] = [NSAttributedString.Key.font: self.userBioTextLabel.font]
  • Coercion of implicitly unwrappable value of type 'UIFont?' to 'Any' does not unwrap optionally
    • Provide a default value to avoid this
    • warning Force-unwrap the value to avoid this warning
    • Explicitly cast to 'Any' with 'as Any' to silence this warning
rishu1992
  • 1,414
  • 3
  • 14
  • 33
  • What is `self.userBioTextLabel`? Is it an IBOutlet? If so, look at https://stackoverflow.com/questions/55422914/why-are-iboutlets-optionals-after-swift-5-migration – Larme Oct 30 '19 at 08:27
  • Does this answer your question? [Why are IBOutlets optionals after swift 5 migration](https://stackoverflow.com/questions/55422914/why-are-iboutlets-optionals-after-swift-5-migration) – Larme Oct 30 '19 at 08:27
  • @IBOutlet weak var userBioTextLabel: UILabel! – rishu1992 Oct 30 '19 at 08:47

1 Answers1

1

It's probably because of your userBioTextLabel , Did you declare it as optional? If so you can force unwrap it , In the outlet declaration line or where you defined it first in your code to fix the warning

MohyG
  • 1,335
  • 13
  • 25