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
You need to make your extension public
if you're defining it in another module:
public extension Double {
var mileToFeet: Double { return self * 5280 }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With