0

I have one array results which I am using to set another array filteredResult which contains some filtered value of the main results array.

var filteredResult: [Result] {
    var result = self.results.filter({ $0.exclusive == true })

    result = result.filter({ $0.name.localizedCaseInsensitiveContains("Test Name") })

    return result
}

Now I will have to perform some task after this filteredResult array is set. So where to perform that task? I have tried didSet after get but I'm getting error

DidSet variable may not also have a get specifier

var filteredResult: [Result] {
    get {
        var result = self.results.filter({ $0.exclusive == true })

        result = result.filter({ $0.name.localizedCaseInsensitiveContains("Test Name") })

        return result
    }
    didSet {

    }
}

I have checked this and this links. But not able to get the solution.

So kindly help me to understand how to perform some task after filteredResult is set with some filter value.

Arnab
  • 4,216
  • 2
  • 28
  • 50
  • 3
    You cannot apply a property observer to a computed property. – vadian Apr 02 '18 at 07:40
  • so where to perform some task after `filteredResult` is set? – Arnab Apr 02 '18 at 07:42
  • At the moment you don't have a setter. `filteredResult` is read-only. Implement the setter (`set { ... }`) and perform the task there. – vadian Apr 02 '18 at 07:44
  • Add the `didSet` to `results`, since I'm guessing that that's a stored property. – Guy Kogus Apr 02 '18 at 07:49
  • Yes I have `didSet` in `results` and used to perform that task from there. But now I'll need to use `filteredResult` to perform that task. – Arnab Apr 02 '18 at 07:50
  • PS: Strictly spoken *Use didSet while initialising a variable* doesn't work anyway because the property observer is not called while initialising a variable. – vadian Apr 02 '18 at 07:51

0 Answers0