What is wrong with this code?
self.callback = { self.attempts += 1 self.downloadFailed() }
There is nothing wrong with this code. Reference: The Swift Programming Language: Language Guide: Automatic Reference Counting: Strong Reference Cycles for Closures
You need to define the type of closure explicitly.
Use of self inside the closure causes retain cycle.
self
You cannot assign a value to a closure in this manner.