Extending an optional Double to convert it to an NSNumber Feb 22, 2022 extension Optional where Wrapped == Double { var asNSNumber : NSNumber? { if let val = self { return NSNumber(floatLiteral: val) } else { return nil } } }