gpt4 book ai didi

ios - 为什么我得到一个 "Value of optional type UIFont not unwrapped",但解包给出 "unexpectedly found nil while unwrapping an optional"?

转载 作者:搜寻专家 更新时间:2023-11-01 05:57:34 26 4
gpt4 key购买 nike

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!
}

相当简单,有问题的 pickerView 是一个 AKPickerView

如果我删除强制解包,我会得到一个编译器错误。 “可选类型 UIFont 的值未展开,您是要使用“!”还是“?”?”

但是,当我强制解包时,出现运行时错误。 “ fatal error :在展开可选值时意外发现 nil”

最佳答案

尝试打印所有可用的字体,并检查字体名称的拼写

 for fontfamily in UIFont.familyNames{
for fontname in UIFont.fontNames(forFamilyName: fontfamily){
print(fontname)
}
}

关于ios - 为什么我得到一个 "Value of optional type UIFont not unwrapped",但解包给出 "unexpectedly found nil while unwrapping an optional"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35553780/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com