Reputation: 6589
func initializePickerViewProperties() {
let font = UIFont (name: "SanFranciscoDisplay-Regular", size: 30.0)
let highlightedFont = UIFont (name: "SanFranciscoDisplay-Bold", size: 35.0)
pickerView.font = font!
pickerView.highlightedFont = highlightedFont!
}
fairly simple, the pickerView in question is an AKPickerView
If I remove the forced unwrapping I get a compiler error. "Value of optional type UIFont not unwrapped, did you mean to use "!" or "?"?"
However, when I force unwrap it, I get a runtime error. "fatal error: unexpectedly found nil while unwrapping an Optional value"
Upvotes: 1
Views: 3347
Reputation: 948
Try printing all available fonts, and check the spelling of your fontname
for fontfamily in UIFont.familyNames{
for fontname in UIFont.fontNames(forFamilyName: fontfamily){
print(fontname)
}
}
Upvotes: 5
Reputation: 163
You must first add your custom font inside your Info.plist.
To look for the Info.plist file:
I solved mine using this. Hope it works for you as well.
Upvotes: 0
Reputation: 1786
Means your fonts are not initialized properly and give nil
. You should safely unwrap them:
func initializePickerViewProperties() {
if let font = UIFont (name: "SanFranciscoDisplay-Regular", size: 30.0),
let highlightedFont = UIFont (name: "SanFranciscoDisplay-Bold", size: 35.0) {
pickerView.font = font
pickerView.highlightedFont = highlightedFont
}
}
Upvotes: 3