Dinalli Dinalli - 6 months ago 15
Swift Question

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?

Answer

It should work, but the syntax would be

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