I am trying to add Custom Fonts in Xcode 10 & I keep getting this error:
Fatal error: Unexpectedly found nil while unwrapping an Optional value
- I have included the fonts in my Info.plist
- I have checked my "Copy Bundle Resources" & It is there.
I still get this error.
This my code below:
DispatchQueue.main.async {
let paragraph = NSMutableParagraphStyle()
paragraph.alignment = .center
let attributedString = NSAttributedString(string: message, attributes:
[.paragraphStyle: paragraph, NSAttributedString.Key.font : UIFont (name: "Lato-Regular", size: 14)!]) // Throws error here
let alert = UIAlertController(title: title, message: "", preferredStyle: .alert)
alert.setValue(attributedString, forKey: "attributedMessage")
alert.addAction(UIAlertAction(title: "Back", style: .cancel, handler: nil))
self.present(alert, animated: true)
}
Throws Error on this line
UIFont (name: "Lato-Regular", size: 14)!
Xcode cannot find font, but I can also use the font on the Storyboard UI. So how come?