0

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]?
        }
    }

}
netwire
  • 7,108
  • 12
  • 52
  • 86
  • can you elaborate that please? do you want to override the property and change it's type? – kap Nov 28 '14 at 08:53
  • Have you tried this solution http://stackoverflow.com/a/24094339/1187415? Can you provide a self-contained example that causes the crash? – Martin R Nov 28 '14 at 09:09

0 Answers0