In java you can do import static MyClass and you'll be able to access the static methods of MyClass without having to prepend them with the class name:
myMethod() instead of MyClass.myMethod()
Is there a way to do this in swift?
I don´t think you can import a static class like Java, it´s a traditional static in Swift where you call it by class name + variable/function.
class MyClass {
static let baseURL = "someURl"
static func myMethod() {
}
}
MyClass.baseURL or MyClass. myMethod.
What you can do is to add a typealias to make an alias for your Static class.
private typealias M = MyClass
And then use the following: M.baseURL or M.myMethod.
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