So I want to add a generic extension to NSNumber,Int,Double and Float where the value is converted to a formatted String.
I started by creating a custom protocol:
protocol MyFormatConvertible {
var toMyFormat: String { get }
}
extension NSNumber: MyFormatConvertible {}
extension Double: MyFormatConvertible {}
extension Float: MyFormatConvertible {}
extension Int: MyFormatConvertible {}
Now I'm trying to add the formatting to the extension:
extension MyFormatConvertible {
public var toMyFormat: String {
let numberValue = NSNumber(value:self)
....
But this doesn't seem to work as I'm getting the error:
Cannot invoke initializer for type 'NSNumber' with an argument list of type '(value: Self)'
Any hints on how to tackle this?