I've found several articles on when you are required to add this to your parameter declarations, But not any on why? Can't the compiler detect this automatically (as it already does with a fixit)?
Why do developers need to be explicit about @escaping closures?
@escaping is already an advanced feature, developer has to understand what it's doing.
And I'm not sure there are not cases where the decision cannot be automatised.
In addition, if it were, some would probably require to keep full control on this.
And I'm not sure there are not cases where the decision cannot be automatised.
In addition, if it were, some would probably require to keep full control on this.
Hmm, it appears you can write @escaping even when it is not escaping.
I don't understand your point.it appears you can write @escaping even when it is not escaping.
If I understand it well, it allows to keep it "alive" after you leave the closure.
Even if you don't need it.
What is critical is to have it purged if you need it after.
So a missing escaping is critical
an extra escaping wastes memory.
It sounds like the same discussion -- why var and let.Can't the compiler detect this automatically (as it already does with a fixit)?
If it is a local variable, the compiler can automatically detect mutating usage and decide var or let automatically.
But what if it is a public property of a class in a library and may be used somewhere outside of your code?
I think there was once a discussion about this in forums.swift.org.
The main topic of this thread is a little bit different than why var and let, but includes some opinion for that.
In my opinion, it is important to declare it explicitly, to help compiler reduce compile time, and to help readers of your code understand the usage of the property.
Nearly the same may happen, when you are writing a method of a class in a library taking a closure.
Anyway, you should better visit forums.swift.org . If you are lucky enough, you may be able to hear some opinions from the core member of Swift Team.