     }
     
 }
-
-private extension CGFloat {
-    
-    var validWeight: CGFloat {
-        let validWeights = FontWeight.rawValues
-        let validWeight = closestInArray(validWeights)
-        return validWeight
-    }
-    
-    func closestInArray(array: [CGFloat]) -> CGFloat {
-        var closest: CGFloat?
-        for possible in array {
-            if closest == nil || abs(possible - self) < abs(closest! - self) {
-                closest = possible
-            }
-        }
-        return closest!
-    }
-    
-}

        if let familyName = flatDict[Key.familyName] as? String {
            attributes[UIFontDescriptorFamilyAttribute] = familyName
            if let weight = flatDict[Key.weight] as? CGFloat {
                let validWeight = weight.validWeight
                let traits = [UIFontWeightTrait: validWeight]
                attributes[UIFontDescriptorTraitsAttribute] = traits
            }

extension UIFont {
    
    func fontWithWeight(weight: CGFloat) -> UIFont {
        let fontWeight = FontWeight.fontWeightForApproximateWeight(weight)
        let traits = [UIFontWeightTrait: fontWeight.rawValue]
        let attributes: TextAttributes = [UIFontDescriptorFamilyAttribute: familyName, UIFontDescriptorTraitsAttribute: traits]
        let descriptor = UIFontDescriptor(fontAttributes: attributes)
        let font = UIFont(descriptor: descriptor, size: pointSize)
