I'm using the lifetime of a variable to push and pop a context in an animation 
system that I'm writing. I'm interested in using a pattern like:

func doAnimations() {
    AnimationContext(speed: 1.0, bounciness: 1.0)
    // do some animations using these options
}

But today, the value returned by AnimationContext(speed:bounciness:) gets 
deinitted immediately.

I've come to desire using such a pattern after living with this for a while:

AnimationContext(speed: 1.0, bounciness: 1.0) {
    // do some animations using these options   
}

But I don't like it because it contributes heavily to rightward drift (a user 
of this API might want to change the options multiple times), and gets hard to 
parse when nested in the many other language constructs that create a scope 
using brackets.

So — would it be reasonable to suggest that we have some keyword(s) preceeding 
an initializer that allows a value to stay alive and/or not warn if it winds up 
going unused? The current behavior in Swift has obviously been considered, so 
please feel free to tell me if this is a Very Bad Idea. I'm still learning!

- Ollie
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to