     
 }
 
+@available(iOS 8.2, *)
 enum FontWeight {
     
     case ultraLight

        if let familyName = flatDict[Key.familyName] as? String {
            attributes[UIFontDescriptorFamilyAttribute] = familyName
            if let weight = flatDict[Key.weight] as? CGFloat {
                let fontWeight = FontWeight.fontWeightForApproximateWeight(weight)
                let validWeight = fontWeight.rawValue
                let traits = [UIFontWeightTrait: validWeight]
                attributes[UIFontDescriptorTraitsAttribute] = traits
            }

        return closest
    }

}

// TODO: move extension to separate file.
extension UIFont {
    
    func fontWithWeight(weight: CGFloat) -> UIFont {
        let validWeight: CGFloat
        if #available(iOS 8.2, *) {
            let fontWeight = FontWeight.fontWeightForApproximateWeight(weight)
            validWeight = fontWeight.rawValue
        } else {
            validWeight = weight
        }
        let traits = [UIFontWeightTrait: validWeight]
        let attributes: TextAttributes = [UIFontDescriptorFamilyAttribute: familyName, UIFontDescriptorTraitsAttribute: traits]
        let descriptor = UIFontDescriptor(fontAttributes: attributes)
        let font = UIFont(descriptor: descriptor, size: pointSize)
