1
當我將Uber SDK集成到我的項目中時,我在swift 2.3中遇到了這個錯誤,但我不知道要解決這個問題。條件綁定的iOS初始化程序必須具有可選類型,而不是'CGFont'?
class FontUtil {
static func loadFontWithName(name: String, familyName: String) -> Bool {
if let path = NSBundle(forClass: FontUtil.self).pathForResource(name, ofType: "otf") {
if let inData = NSData(contentsOfFile: path) {
var error: Unmanaged<CFError>?
let cfdata = CFDataCreate(nil, UnsafePointer<UInt8>(inData.bytes), inData.length)
if let provider = CGDataProviderCreateWithCFData(cfdata) {
if let font = CGFontCreateWithDataProvider(provider) ---> Error found in this line {
if (CTFontManagerRegisterGraphicsFont(font, &error)) {
return true
}
print("Failed to load font with error: \(error)")
}
}
}
}
return false
}}
解決方法是在您放入標題的錯誤消息中給出的。 :)提示:在之前的Swift版本中返回一個Optional的東西現在不再返回Optional了... – Moritz