I've built this struct to handle a specific type of data I plan on using in some custom classes.
My issue is that featureSubSet variable is capable of being one of a few enums, and when this struct is initialized it wont know which enum it will be, so I declared it as Any.
When the public init is called, it will appropriately funnel the data to the needed private init method so that it can properly and fully be initialized.
I get the error at the end of the public init method, but I'm not sure how to get it to go away.
struct Feature {
//MARK: Variables needed for Feature
var featureSet: FeatureType
var featureSubSet: Any
var effect: String
var active: Bool?
var skill: Skill?
var ability: Ability?
public init(base: String, sub: String, effect: String, skill: Skill? = nil, ability: Ability? = nil) {
switch base {
case featureCategoryList()[0]: // Character Features
self.init(CharacterFeature: sub, effect: effect)
case featureCategoryList()[1]: // Combat Features
self.init(CombatFeature: sub, effect: effect)
case featureCategoryList()[2]: //Skill Features
guard let newSkill = skill else {
print("No skill")
return
}
self.init(SkillFeature: sub, effect: effect, skill: newSkill)
default:
print("Somehow you picked something not on the list.")
break
}
}
private init(CharacterFeature sub: String, effect: String) {
self.featureSet = .CharacterFeatures
self.featureSubSet = CharacterFeatures.init(rawValue: sub)!
self.effect = effect
}
private init(CombatFeature sub: String, effect: String) {
self.featureSet = .CombatFeatures
self.featureSubSet = CharacterFeatures.init(rawValue: sub)!
self.effect = effect
}
private init(SkillFeature sub: String, effect: String, skill: Skill) {
self.featureSet = .SkillFeatures
self.featureSubSet = CharacterFeatures.init(rawValue: sub)!
self.skill = skill
self.effect = effect
}
//MARK: Feature functions
func string() -> String {
//TODO: Make a string output for what the feature is.
return ""
}
}