iosobjective-cswiftkey-value-codingcaemittercell

Is KVC possible with Swift?


I'm trying to create the equivalent of the following Objective-C in Swift.

[emitterLayer setValue:@ (scale) forKeyPath:@"emitterCells.cell.emitterCells.childCell.scale"];

I have tried the following in Swift:

emitterLayer.setValue (scale), forKey: "emitterCells.cell.emitterCells.childCell.scale")

However this does not change the value as it would in objective-C

Does this work in Swift or do I need to refactor this to work differently to achieve the same result?


Solution

  • It should work, but the syntax would be

    emitterKayer.setValue(scale, 
      forKeyPath:  "emitterCells.cell.emitterCells.childCell.scale")