I’m trying to call a function that takes in an Array as a reference
<code>spill(pool: &objectPool)
</code>
<code>spill(pool: &objectPool)
</code>
spill(pool: &objectPool)
And the function will make the array pops its first element to run some animations. Once the animation is complete, the element gets put back to the Array
<code> func spill(pool: inout [Object]) {
let spill = pool[0]
spriteComponent.node.addChild(spill.sprite)
pool.removeFirst()
spill.sprite.run(SKAction.sequence([spill.spriteAnimation, SKAction.removeFromParent()])) {
pool.append(spill)
//Do some other works
}
}
</code>
<code> func spill(pool: inout [Object]) {
let spill = pool[0]
spriteComponent.node.addChild(spill.sprite)
pool.removeFirst()
spill.sprite.run(SKAction.sequence([spill.spriteAnimation, SKAction.removeFromParent()])) {
pool.append(spill)
//Do some other works
}
}
</code>
func spill(pool: inout [Object]) {
let spill = pool[0]
spriteComponent.node.addChild(spill.sprite)
pool.removeFirst()
spill.sprite.run(SKAction.sequence([spill.spriteAnimation, SKAction.removeFromParent()])) {
pool.append(spill)
//Do some other works
}
}
However, I get the following error message:
<code>Escaping closure captures 'inout' parameter 'pool'
</code>
<code>Escaping closure captures 'inout' parameter 'pool'
</code>
Escaping closure captures 'inout' parameter 'pool'
How do I get this function to work?
Thanks in advance.