Is putting your class inside a struct an acceptable way to namespace your class in Swift? I did not see any mention of nested struct or struct-class in the programming guide.
struct TestNamespace {
class Test {
}
}
Is putting your class inside a struct an acceptable way to namespace your class in Swift? I did not see any mention of nested struct or struct-class in the programming guide.
struct TestNamespace {
class Test {
}
}
I'd be (even more) happy with namespaces in Swift, because they help organize the code more granularly. If you're experimenting with using struct
as a namespace, consider disabling its construction:
struct PseudoNamespace {
private init() {}
//...
}
Using struct
has an advantage over using class
: structs does not support inheritance and with classes it needs using final
modifier.
One significant disadvantage of this emulation is that there is no way no "import" such a namespace (like import PseudoNamespace.*
, etc.), because Swift allows importing modules, but not structs.