【发布时间】:2016-05-08 17:36:56
【问题描述】:
我正在尝试在 Swift 中创建与以下 Objective-C 等效的内容。
[emitterLayer setValue:@ (scale) forKeyPath:@"emitterCells.cell.emitterCells.childCell.scale"];
我在 Swift 中尝试过以下方法:
emitterLayer.setValue (scale), forKey: "emitterCells.cell.emitterCells.childCell.scale")
但是这不会像在 Objective-C 中那样改变值
这在 Swift 中是否有效,或者我是否需要对其进行重构以以不同的方式工作以达到相同的结果?
【问题讨论】:
-
scale是值类型吗?将其包裹在NSNumber中。 -
forKey与forKeyPath? -
这是 KVC,不是 KVO。
标签: ios objective-c swift key-value-coding caemittercell