Skip to content

Instantly share code, notes, and snippets.

@djds23
Created March 2, 2021 03:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djds23/aa720d66ad2af7e1d24d33ae29f49534 to your computer and use it in GitHub Desktop.
Save djds23/aa720d66ad2af7e1d24d33ae29f49534 to your computer and use it in GitHub Desktop.
An SKAction that writes a value to a specified object.
extension SKAction {
static func write<Root: AnyObject, Value>(
value: Value,
to keyPath: ReferenceWritableKeyPath<Root, Value>,
on object: Root
) -> SKAction {
SKAction.customAction(withDuration: 0) { [weak object] _, _ in
object?[keyPath: keyPath] = value
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment