Swift: How to create a global extension to use everywhere for a Double or Int?

Viewed 2379

Here's my problem: I am trying to create a global extension for Double (or Int) which can be used in every ViewController without repeating the code at the top of every ViewController file.

for instance:

extension Double {
    var mileToFeet: Double {return self * 5280}
}

Of course I can call it like this:

let feet = 26.mileToFeet

Obviously this works when I put the extension at the top of the ViewController and use it withing the code, but where can I place extension so that I can use it everywhere?

I tried to put it into AppDelegate, but that doesn't work? Am I on the right track there?

Thanks

2 Answers
Related