条件绑定的初始化程序必须具有可选类型,而不是' CGFont'

时间:2016-10-02 12:57:58

标签: ios swift swift2 swift3

嗨,大家好我最近在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
        }
    }

我不知道该怎么办请帮忙。

0 个答案:

没有答案