嗨,大家好我最近在swift 2.2中遇到了这个错误..叫做UberRides SDK Initializer for conditional binding must have Optional type, not '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) {
// The error is in the line below
if let font = CGFontCreateWithDataProvider(provider) {
if (CTFontManagerRegisterGraphicsFont(font, &error)) {
return true
}
print("Failed to load font with error: \(error)")
}
}
}
}
return false
}
}
我不知道该怎么办请帮忙。