@noescape optimized compiler compilation, introduced by Swift 2.1.
function if there is a parameter is closure, you can add a keyword @noescape before the function return closure the end of the life cycle, you can optimize the compilation. (Closure is a reference type that can be referenced elsewhere, as follows:)
class a{var B: (void void ) Func Lalala (A: (void ->, void )) {self b = a//reference to Property B }}
as in the case above Lalala parameter A is not marked @noescape
class a{var B: (void void ) Func AA (@noescape A: (void ->, void )) {self b = a//will report the error, the type is not the same }}
class a {var b: void , void ) ! Func aanoescape void ->void ) ) {A () //No error, this will not be called again externally}}
@noescape also has a feature that marks the @noescape closure can eliminate the write reference self. Swift's normal closure is required when using self. This can be an exception. Because he is equivalent to a synchronous call and does not produce a circular reference, so do not deliberately emphasize self
Class a{varB: (Void -Void)! varK= 0//Used to invoke theFunc AA (@noescape A: (Void -Void) {A ()} func bb () {aa {()} -Void inchK= 1//General closure are to SELF.K = 1, @noescape do not need} }}
Discussion: When will the @noescape be used? Now a lot of functional programming, such as having a sort, requires a comparison of the closure as a parameter, this closure will be the synchronous call complete to get the return value. This can put a @noescape in front, can optimize memory, reference self does not have to write self. Other closure that are externally referenced by the wait will not be @noescape, because it will escape. Generally speaking, this @noescape is not a good egg, but some people will use it, it may scare you. For example, I saw a use of this yesterday, this basic can be ignored. Apple Documentation Links
Swift2.1 Keyword @noescape Introduction