I have a ParentController
and ChildController
as below. The ParentController holds an array of [AnyObject]?
and the child class holds an array of specific models (i.e. Merchant
). The parent class has methods that references the results
array, hence I've declared it as [AnyObject]?
.
Is there a way that I can override the results
array in ChildController
?
Rationale: I had tried results.append()
originally in ChildController
, but apparently that causes issues due to downcasting. The problem was sporadic, so hard to explain. However, after about a week of research and trial & error, I think the only way to solve this is to create a separate array in the ChildController
to hold data, but still be accessible by methods in the parent class. Thoughts?
class ParentClass: UIViewController {
var results: [AnyObject]?
//has methods that reference results array
}
class ChildClass: ParentClass {
var merchants: [Merchant]?
override var results: [AnyObject]? {
get {
return self.merchants as [AnyObject]?
//this doesn't work, gives EXC_BAD_ACCESS error
}
set {
super.results = self.merchants as [AnyObject]?
}
}
}