I've the following base enum:
enum Voicity {}
On various different files, I extend the above enum to store various functions and information that is used by my app as a central station.
For instance, I use this enum to create my UI elements programmatically.
extension Voicity {
enum sectionObject {
case textField(ofType: Voicity.UIElement.textField)
case button(ofType: Voicity.UIElement.button)
case label(ofType: Voicity.UIElement.label)
case line()
case photoCircle
case stackView(_: UIStackView)
case view(_: UIView)
var item: UIView {
switch self {
case .textField(let type):
return createTextField(ofType: type)
case .label(let type):
return createLabel(ofType: type)
case .line():
return createLine()
case .photoCircle:
return createPhotoCircle()
case .stackView(let view):
return view
case .view(let view):
return view
case .button(let type):
return createButton(ofType: type)
}
}
}
}
For readability/maintainability, I separated the returned functions above into separate files as well by again extending the sectionObject
enum.
extension Voicity.sectionObject {
func createLabel(ofType type: Voicity.UIElement.label) -> UILabel {
// implementation here
}
}
The above works fine but when I try to declare the createButton()
:
extension Voicity.sectionObject {
func createButton(ofType type: Voicity.UIElement.button) -> UIButton {
// implementation here
}
}
I get the following error:
sectionObject is not a member of Voicity
.
Why can't I extend my enum on one file when I can do so in another?
Update
createButton()
and createLabel()
methods are both inside group/folder Model
.
The enum declarations are inside group/folder Store
.
So, they are separated. But it amazes me that createLabel()
works when createButton()
can't.
It all used to work(methods being in different files) when my enum cases were all in a single file again under group/folder Store
and methods under group/folder Model
. I needed to refactor my enum cases when they enlarged.
Moreover, I just now tried moving createButton()
inside the extension declaring createLabel()
. And it all works for some reason.
Previously, I deleted the file declaring the createButton()
method and recreated it and everything is the same. Therefore it's not some weird Xcode parsing issue.