Avoiding state
The first rule is to avoid a state. When you are doing two things at the same time, those two processes should be as independent and isolated as possible. They shouldn't know anything about each other or share any mutable resources. If they do, then we would need to take care of synchronizing access to that shared resource, which would bring a complexity to our system that we don't want. Right now in our code we have two states: a revenue
numbers array and the average
result. Both of the processes have access to that state.
The first problem in that the code is referencing itself. When you try to access an instance variable or a method that is out of the closure scope, you see an error message: Reference to property 'revenue' in closure requires explicit 'self.' to make capture semantics explicit.
Xcode would also propose a fix to this issue, adding explicit self-capturing. This would solve the Xcode error but it wouldn't solve the root problem. When you see this error, stop...